home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6647 / 6647.xpi / components / HttpFoxService.js
Text File  |  2009-04-10  |  105KB  |  3,546 lines

  1. /*
  2.     HttpFox - An HTTP analyzer addon for Firefox
  3.     Copyright (C) 2008 Martin Theimer
  4.     
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.     
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.     
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /***********************************************************
  21. constants
  22. ***********************************************************/
  23. // reference to the interface defined in nsIHelloWorld.idl
  24. //const nsIHelloWorld = Components.interfaces.nsIHelloWorld;
  25.  
  26. // reference to the required base interface that all components must support
  27. const nsISupports = Components.interfaces.nsISupports;
  28.  
  29. // UUID uniquely identifying our component
  30. const CLASS_ID = Components.ID("{307fd88d-5c81-4487-bb0d-42e228a68767}");
  31.  
  32. // description
  33. const CLASS_NAME = "HttpFox Service";
  34.  
  35. // textual unique identifier
  36. const CONTRACT_ID = "@decoded.net/httpfox;1";
  37.  
  38.  
  39. /***********************************************************
  40. class definition
  41. ***********************************************************/
  42. //class constructor
  43. function HttpFoxService() 
  44. {
  45.     this.wrappedJSObject = this;
  46.     this.init();
  47. };
  48.  
  49. // class definition
  50. HttpFoxService.prototype = 
  51. {
  52.     // Controller/Interface list
  53.     Controllers: null,
  54.     
  55.     // Request Observer
  56.     Observer: null,
  57.  
  58.     // All requests (holds HttpFoxRequest objects)
  59.     Requests: null,
  60.  
  61.     // All pending requests (isPending == true)
  62.     PendingRequests: null,
  63.  
  64.     // session start timestamp
  65.     StartTime: null,
  66.     
  67.     // is observer currently running
  68.     IsWatching: false,
  69.     
  70.     // user preferences
  71.     Preferences: null,
  72.     
  73.     // detach window reference
  74.     HttpFoxWindow: null,
  75.     
  76.     init: function() 
  77.     {
  78.         this.Controllers = new Array();
  79.         
  80.         this.Requests = new Array();
  81.         this.PendingRequests = new Array();
  82.         
  83.         this.StartTime = new Date();
  84.         
  85.         this.Observer = new HttpFoxObserver(this);
  86.         
  87.         this.Preferences = new HttpFoxPreferences();
  88.         
  89.         if (this.Preferences.StartAtBrowserStart)
  90.         {
  91.             this.startWatching();
  92.         }
  93.     },
  94.     
  95.     addController: function(HttpFoxControllerReference)
  96.     {
  97.         this.Controllers.push(HttpFoxControllerReference);
  98.         HttpFoxControllerReference.ControllerIndex = this.Controllers.length;
  99.     },
  100.     
  101.     removeController: function(HttpFoxControllerReference)
  102.     {
  103.         for (var i = 0; i < this.Controllers.length; i++)
  104.         {
  105.             if (this.Controllers[i] === HttpFoxControllerReference)
  106.             {
  107.                 this.Controllers.splice(i, 1);
  108.                 break;
  109.             }
  110.         }
  111.     },
  112.     
  113.     startWatching: function() 
  114.     {
  115.         this.Observer.start();
  116.         this.IsWatching = true;
  117.     },
  118.     
  119.     stopWatching: function() 
  120.     {
  121.         this.Observer.stop();
  122.         this.IsWatching = false;
  123.     },
  124.     
  125.     clearRequests: function()
  126.     {
  127.         this.Requests = new Array();
  128.         this.PendingRequests = new Array();
  129.         
  130.         this.StartTime = new Date();
  131.     },
  132.     
  133.     windowIsClosed: function()
  134.     {
  135.         this.callControllerMethod("windowIsClosed");
  136.     },
  137.     
  138.     callControllerMethod: function(methodName, parameterArray)
  139.     {
  140.         for (var c in this.Controllers)
  141.         {
  142.             this.Controllers[c][methodName].call(this.Controllers[c], parameterArray);
  143.         }
  144.     },
  145.     
  146.     isNewRequest: function(request)
  147.     {
  148.         return (this.getPendingRequestForRequestEvent(request) == -1) ? true : false;
  149.     },
  150.     
  151.     getPendingRequestForRequestEvent: function(request)
  152.     {
  153.         // check for matching request
  154.         for (var i = 0; i < this.Requests.length; i++) 
  155.         {
  156.             if (request.HttpChannel === this.Requests[i].HttpChannel) 
  157.             {
  158.                 return i;
  159.             }
  160.         }
  161.         
  162.         // no match found
  163.         return -1;
  164.     },
  165.     
  166.     // thanks to tamper data:
  167.     forceCaching: function(request) {
  168.         // we only care if we were a POST, GET's cache no matter what
  169.         if (request.requestMethod == "POST") 
  170.         {
  171.             if (request.loadFlags & Components.interfaces.nsIRequest.INHIBIT_CACHING) 
  172.             {
  173.                 if (this.Preferences.ForceCaching) 
  174.                 {
  175.                     request.loadFlags = request.loadFlags & ~Components.interfaces.nsIRequest.INHIBIT_CACHING;
  176.                 }
  177.             }
  178.         }
  179.     },
  180.     
  181.     addNewRequest: function(requestEvent)
  182.     {
  183.         // a new request
  184.         var request = new HttpFoxRequest(requestEvent.HttpFox, requestEvent.HttpChannel, requestEvent.Context, requestEvent);
  185.         this.Requests.push(request);
  186.         this.PendingRequests.push(request);
  187.         
  188.         // check filter
  189.         this.callControllerMethod("filterRequest", {"p1" : request});
  190.         
  191.         // start checking
  192.         if (this.IntervalChecker == null)
  193.         {
  194.             this.IntervalChecker = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  195.             var callback = 
  196.             {
  197.                 notify: function(timer) 
  198.                 {
  199.                     this.parent.checkPendingRequests();
  200.                     return;
  201.                 }
  202.             };
  203.             callback.parent = this;
  204.             this.IntervalChecker.initWithCallback(callback, 10, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
  205.         }
  206.     },
  207.     
  208.     updateRequest: function(index, updatedRequest)
  209.     {
  210.         this.Requests[index].updateFromRequestEvent(updatedRequest);
  211.  
  212.         this.callControllerMethod("redrawRequestTree", {"p1": index});
  213.     },
  214.     
  215.     //M
  216.     checkPendingRequests: function()
  217.     {
  218.         try 
  219.         {
  220.             var before = this.PendingRequests.length;
  221.             for (var i = 0; i < this.PendingRequests.length; i++)
  222.             {
  223.                 if (!this.PendingRequests[i].HttpChannel.isPending() && !this.PendingRequests[i].IsFinal)
  224.                 {
  225.                     // complete request. release channel reference.
  226.                     var requestIndex = this.getPendingRequestForRequestEvent(this.PendingRequests[i]);
  227.                     this.PendingRequests[i].complete();
  228.                     this.callControllerMethod("redrawRequestTree", {"p1": requestIndex});
  229.                     this.PendingRequests.splice(i, 1);
  230.                     i--;
  231.                 }
  232.             }
  233.             
  234.             if (this.PendingRequests.length == 0) 
  235.             {
  236.                 if (this.IntervalChecker != null)
  237.                 {
  238.                     this.IntervalChecker.cancel();
  239.                     this.IntervalChecker = null;
  240.                 }
  241.             }
  242.             
  243.             //this.callControllerMethod("redrawRequestTree")
  244.         }
  245.         catch(e)
  246.         {}
  247.     },
  248.     
  249.     //C
  250.     handleRequestEvent: function(requestEvent)
  251.     {
  252.         // checking pending requests
  253.         this.checkPendingRequests();
  254.         
  255.         // check if this is a http request:
  256.         try 
  257.         {
  258.             requestEvent.HttpChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
  259.         }
  260.         catch (ex) 
  261.         {
  262.             return;
  263.         }
  264.         
  265.         // check if this is just our response content loader
  266.         if (!this.Preferences.ShowHttpFoxHelperRequests && requestEvent.HttpChannel.owner) 
  267.         {
  268.             try 
  269.             {
  270.                 if (requestEvent.HttpChannel.owner.QueryInterface(Components.interfaces.nsISupportsString).data == "HttpFoxResponseLoaderFlagger") 
  271.                 {
  272.                     // don't log.
  273.                     return;
  274.                 }
  275.             }
  276.             catch(ex) 
  277.             {}
  278.         }
  279.         
  280.         switch(requestEvent.EventSource) 
  281.         {
  282.             case this.HttpFoxEventSourceType.ON_MODIFY_REQUEST:
  283.             case this.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE:
  284.             case this.HttpFoxEventSourceType.ON_EXAMINE_MERGED_RESPONSE:
  285.             case this.HttpFoxEventSourceType.EVENTSINK_ON_PROGRESS:
  286.             case this.HttpFoxEventSourceType.EVENTSINK_ON_STATUS:
  287.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_STATUS_CHANGED:
  288.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_STATE_CHANGED:
  289.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_SECURITY_CHANGED:
  290.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_PROGRESS_CHANGED:
  291.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_LOCATION_CHANGED:
  292.                 //find matching request 
  293.                 var index = this.getPendingRequestForRequestEvent(requestEvent);
  294.                 if (index == -1)
  295.                 {
  296.                     if (requestEvent.EventSource != this.HttpFoxEventSourceType.ON_MODIFY_REQUEST) 
  297.                     {
  298.                         //only ON_MODIFY_REQUEST can be a new one. discard other types
  299.                         return;
  300.                     }
  301.                     // new request. add.
  302.                     this.addNewRequest(requestEvent);
  303.                     
  304.                     // not found. not good. TODO: handling
  305.                 }
  306.                 else 
  307.                 {
  308.                     this.updateRequest(index, requestEvent);
  309.                 }
  310.                 break;
  311.         }
  312.     },
  313.     
  314.     getStatusTextFromCode: function(HttpFoxStatusCode, status)
  315.     {
  316.         var statusText = "";
  317.         switch(HttpFoxStatusCode)
  318.         {
  319.             case this.HttpFoxStatusCodeType.SOCKETTRANSPORT:
  320.                 switch(status)
  321.                 {
  322.                     case Components.interfaces.nsISocketTransport.STATUS_RESOLVING:
  323.                         statusText = "STATUS_RESOLVING";
  324.                         break;
  325.                         
  326.                     case Components.interfaces.nsISocketTransport.STATUS_CONNECTING_TO:
  327.                         statusText = "STATUS_CONNECTING_TO";
  328.                         break;
  329.                         
  330.                     case Components.interfaces.nsISocketTransport.STATUS_CONNECTED_TO:
  331.                         statusText = "STATUS_CONNECTED_TO";
  332.                         break;
  333.                         
  334.                     case Components.interfaces.nsISocketTransport.STATUS_SENDING_TO:
  335.                         statusText = "STATUS_SENDING_TO";
  336.                         break;
  337.                         
  338.                     case Components.interfaces.nsISocketTransport.STATUS_WAITING_FOR:
  339.                         statusText = "STATUS_WAITING_FOR";
  340.                         break;
  341.                         
  342.                     case Components.interfaces.nsISocketTransport.STATUS_RECEIVING_FROM:
  343.                         statusText = "STATUS_RECEIVING_FROM";
  344.                         break;
  345.                         
  346.                     case Components.interfaces.nsITransport.STATUS_READING:
  347.                         statusText = "STATUS_READING";
  348.                         break;
  349.                         
  350.                     case Components.interfaces.nsITransport.STATUS_WRITING:
  351.                         statusText = "STATUS_WRITING";
  352.                         break;
  353.                         
  354.                     default:
  355.                         statusText = "UNKOWN CODE (" + status + ")";
  356.                         break;
  357.                 }
  358.                 break;
  359.                 
  360.             case this.HttpFoxStatusCodeType.WEBPROGRESS_TRANSITION:
  361.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_START)
  362.                 {
  363.                     statusText = "STATE_START";
  364.                 }
  365.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_REDIRECTING)
  366.                 {
  367.                     statusText = "STATE_REDIRECTING";
  368.                 }
  369.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_TRANSFERRING)
  370.                 {
  371.                     statusText = "STATE_TRANSFERRING";
  372.                 }
  373.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_NEGOTIATING)
  374.                 {
  375.                     statusText = "STATE_NEGOTIATING";
  376.                 }
  377.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_STOP)
  378.                 {
  379.                     statusText = "STATE_STOP";
  380.                 }
  381.                 break;
  382.                 
  383.             case this.HttpFoxStatusCodeType.WEBPROGRESS_TYPE:
  384.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_IS_REQUEST)
  385.                 {
  386.                     statusText += "STATE_IS_REQUEST ";
  387.                 }
  388.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_IS_DOCUMENT) 
  389.                 {
  390.                     statusText += "STATE_IS_DOCUMENT ";
  391.                 }
  392.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK) 
  393.                 {
  394.                     statusText += "STATE_IS_NETWORK ";
  395.                 }
  396.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW) 
  397.                 {
  398.                     statusText += "STATE_IS_WINDOW ";
  399.                 }
  400.                 statusText = statusText.substr(0, statusText.length - 1);
  401.                 break;
  402.             
  403.             case this.HttpFoxStatusCodeType.WEBPROGRESS_MODIFIER:    
  404.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_RESTORING) 
  405.                 {
  406.                     statusText = "STATE_IS_RESTORING";
  407.                 }
  408.                 break;
  409.                 
  410.             case this.HttpFoxStatusCodeType.WEBPROGRESS_SECURITY:
  411.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_IS_INSECURE) 
  412.                 {
  413.                     statusText = "STATE_IS_INSECURE";
  414.                 }
  415.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_IS_BROKEN) 
  416.                 {
  417.                     statusText = "STATE_IS_BROKEN";
  418.                 }
  419.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE) 
  420.                 {
  421.                     statusText = "STATE_IS_SECURE";
  422.                 }
  423.                 break;
  424.                 
  425.             case this.HttpFoxStatusCodeType.WEBPROGRESS_SECURITY_STRENGTH:
  426.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_SECURE_HIGH) 
  427.                 {
  428.                     statusText = "STATE_SECURE_HIGH";
  429.                 }
  430.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_SECURE_MED) 
  431.                 {
  432.                     statusText = "STATE_SECURE_MED";
  433.                 }
  434.                 if (status & Components.interfaces.nsIWebProgressListener.STATE_SECURE_LOW) 
  435.                 {
  436.                     statusText = "STATE_SECURE_LOW";
  437.                 }
  438.                 break;
  439.                 
  440.             case this.HttpFoxStatusCodeType.LOADFLAGS_CHANNEL:
  441.                 if (status & Components.interfaces.nsIChannel.LOAD_DOCUMENT_URI) 
  442.                 {
  443.                     statusText += "LOAD_DOCUMENT_URI ";
  444.                 }
  445.                 if (status & Components.interfaces.nsIChannel.LOAD_RETARGETED_DOCUMENT_URI) 
  446.                 {
  447.                     statusText += "LOAD_RETARGETED_DOCUMENT_URI ";
  448.                 }
  449.                 if (status & Components.interfaces.nsIChannel.LOAD_INITIAL_DOCUMENT_URI) 
  450.                 {
  451.                     statusText += "LOAD_INITIAL_DOCUMENT_URI ";
  452.                 }
  453.                 if (status & Components.interfaces.nsIChannel.LOAD_REPLACE) 
  454.                 {
  455.                     statusText += "LOAD_REPLACE ";
  456.                 }
  457.                 if (status & Components.interfaces.nsIChannel.LOAD_TARGETED) 
  458.                 {
  459.                     statusText += "LOAD_TARGETED ";
  460.                 }
  461.                 statusText = statusText.substr(0, statusText.length - 1);
  462.                 break;
  463.                 
  464.             case this.HttpFoxStatusCodeType.LOADFLAGS_REQUEST:
  465.                 if (status & Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE) 
  466.                 {
  467.                     statusText += "LOAD_BYPASS_CACHE ";
  468.                 }
  469.                 if (status & Components.interfaces.nsIRequest.LOAD_BACKGROUND) 
  470.                 {
  471.                     statusText += "LOAD_BACKGROUND ";
  472.                 }
  473.                 if (status & Components.interfaces.nsIRequest.INHIBIT_CACHING) 
  474.                 {
  475.                     statusText += "INHIBIT_CACHING ";
  476.                 }
  477.                 if (status & Components.interfaces.nsIRequest.INHIBIT_PERSISTENT_CACHING) 
  478.                 {
  479.                     statusText += "INHIBIT_PERSISTENT_CACHING ";
  480.                 }
  481.                 if (status & Components.interfaces.nsIRequest.LOAD_FROM_CACHE) 
  482.                 {
  483.                     statusText += "LOAD_FROM_CACHE ";
  484.                 }
  485.                 if (status & Components.interfaces.nsIRequest.VALIDATE_ALWAYS) 
  486.                 {
  487.                     statusText += "VALIDATE_ALWAYS ";
  488.                 }
  489.                 if (status & Components.interfaces.nsIRequest.VALIDATE_NEVER) 
  490.                 {
  491.                     statusText += "VALIDATE_NEVER ";
  492.                 }
  493.                 if (status & Components.interfaces.nsIRequest.VALIDATE_ONCE_PER_SESSION) 
  494.                 {
  495.                     statusText += "VALIDATE_ONCE_PER_SESSION ";
  496.                 }
  497.                 statusText = statusText.substr(0, statusText.length - 1);
  498.                 break;
  499.                 
  500.             case this.HttpFoxStatusCodeType.LOADFLAGS_CACHING:
  501.                 if (status & Components.interfaces.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE) 
  502.                 {
  503.                     statusText += "LOAD_BYPASS_LOCAL_CACHE ";
  504.                 }
  505.                 if (status & Components.interfaces.nsICachingChannel.LOAD_ONLY_FROM_CACHE) 
  506.                 {
  507.                     statusText += "LOAD_ONLY_FROM_CACHE ";
  508.                 }
  509.                 if (status & Components.interfaces.nsICachingChannel.LOAD_ONLY_IF_MODIFIED) 
  510.                 {
  511.                     statusText += "LOAD_ONLY_IF_MODIFIED ";
  512.                 }
  513.                 if ((Components.interfaces.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY) && 
  514.                       (status & Components.interfaces.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY))
  515.                 {
  516.                     statusText += "LOAD_BYPASS_LOCAL_CACHE_IF_BUSY ";
  517.                 }
  518.                 statusText = statusText.substr(0, statusText.length - 1);
  519.                 break;
  520.                 
  521.             default:
  522.                 statusText = "UNKOWN STATUSCODETYPE";
  523.                 break;
  524.         }
  525.         
  526.         return statusText;
  527.     },
  528.  
  529.     getEventSourceName: function(EventSource)
  530.     {
  531.         switch(EventSource)
  532.         {
  533.             case this.HttpFoxEventSourceType.ON_MODIFY_REQUEST:
  534.                 return "ON_MODIFY_REQUEST";
  535.                 break;
  536.                 
  537.             case this.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE:
  538.                 return "ON_EXAMINE_RESPONSE";
  539.                 break;
  540.                 
  541.             case this.HttpFoxEventSourceType.ON_EXAMINE_MERGED_RESPONSE:
  542.                 return "ON_EXAMINE_MERGED_RESPONSE";
  543.                 break;
  544.                 
  545.             case this.HttpFoxEventSourceType.EVENTSINK_ON_PROGRESS:
  546.                 return "EVENTSINK_ON_PROGRESS";
  547.                 break;
  548.                 
  549.             case this.HttpFoxEventSourceType.EVENTSINK_ON_STATUS:
  550.                 return "EVENTSINK_ON_STATUS";
  551.                 break;
  552.                 
  553.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_STATUS_CHANGED:
  554.                 return "WEBPROGRESS_ON_STATUS_CHANGED";
  555.                 break;
  556.                 
  557.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_STATE_CHANGED:
  558.                 return "WEBPROGRESS_ON_STATE_CHANGED";
  559.                 break;
  560.                 
  561.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_SECURITY_CHANGED:
  562.                 return "WEBPROGRESS_ON_SECURITY_CHANGED";
  563.                 break;
  564.                 
  565.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_PROGRESS_CHANGED:
  566.                 return "WEBPROGRESS_ON_PROGRESS_CHANGED";
  567.                 break;
  568.                 
  569.             case this.HttpFoxEventSourceType.WEBPROGRESS_ON_LOCATION_CHANGED:
  570.                 return "WEBPROGRESS_ON_LOCATION_CHANGED";
  571.                 break;
  572.                 
  573.             case this.HttpFoxEventSourceType.SCANNED_COMPLETE:
  574.                 return "SCANNED_COMPLETE (manual)";
  575.                 break;
  576.                 
  577.             default:
  578.                 return "UNKOWN EVENTSOURCE TYPE";
  579.                 break;
  580.         }
  581.         
  582.         return null;
  583.     },
  584.  
  585.     QueryInterface: function(aIID)
  586.     {
  587.         if (!aIID.equals(nsISupports))
  588.         {
  589.             throw Components.results.NS_ERROR_NO_INTERFACE;
  590.         }
  591.         return this;
  592.     }
  593. };
  594.  
  595. HttpFoxService.prototype.HttpFoxEventSourceType = 
  596. {
  597.     ON_MODIFY_REQUEST: 0,
  598.     ON_EXAMINE_RESPONSE: 1,
  599.     ON_EXAMINE_MERGED_RESPONSE: 2,
  600.     EVENTSINK_ON_PROGRESS: 3,
  601.     EVENTSINK_ON_STATUS: 4,
  602.     WEBPROGRESS_ON_STATUS_CHANGED: 5,
  603.     WEBPROGRESS_ON_STATE_CHANGED: 6,
  604.     WEBPROGRESS_ON_SECURITY_CHANGED: 7,
  605.     WEBPROGRESS_ON_PROGRESS_CHANGED: 8,
  606.     WEBPROGRESS_ON_LOCATION_CHANGED: 9,
  607.     SCANNED_COMPLETE: 10
  608. }; 
  609.  
  610. HttpFoxService.prototype.HttpFoxStatusCodeType =
  611. {
  612.     SOCKETTRANSPORT: 0,
  613.     WEBPROGRESS_TRANSITION: 1,
  614.     WEBPROGRESS_TYPE: 2,
  615.     WEBPROGRESS_SECURITY: 3,
  616.     WEBPROGRESS_SECURITY_STRENGTH: 4,
  617.     WEBPROGRESS_MODIFIER: 5,
  618.     LOADFLAGS_REQUEST: 6,
  619.     LOADFLAGS_CHANNEL: 7,
  620.     LOADFLAGS_CACHING: 8
  621. };
  622.  
  623. function HttpFoxPreferences() 
  624. {
  625.     this.init();
  626. };
  627.  
  628. HttpFoxPreferences.prototype = 
  629. {
  630.     prefs: null,
  631.     
  632.     // Options
  633.     _StartAtBrowserStart: null,
  634.     
  635.     _AlwaysOpenDetached: null,
  636.     
  637.     _ShowHttpFoxHelperRequests: null,
  638.     
  639.     _ColorRequests: null,
  640.     
  641.     _ShowDebugTab: null,
  642.     
  643.     _ForceCaching: null,
  644.         
  645.     init: function() 
  646.     {
  647.         // Register to receive notifications of preference changes
  648.         this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
  649.             .getService(Components.interfaces.nsIPrefService)
  650.             .getBranch("extensions.httpfox.");
  651.         this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
  652.         this.prefs.addObserver("", this, false);
  653.     
  654.         // init values
  655.         this._StartAtBrowserStart = this.prefs.getBoolPref("StartAtBrowserStart");
  656.         this._AlwaysOpenDetached = this.prefs.getBoolPref("AlwaysOpenDetached");
  657.         this._ShowHttpFoxHelperRequests = this.prefs.getBoolPref("ShowHttpFoxHelperRequests");
  658.         this._ColorRequests = this.prefs.getBoolPref("ColorRequests");
  659.         this._ShowDebugTab = this.prefs.getBoolPref("ShowDebugTab");
  660.         this._ForceCaching = this.prefs.getBoolPref("ForceCaching");
  661.     },
  662.     
  663.     shutdown: function()
  664.     {
  665.         this.prefs.removeObserver("", this);
  666.     },
  667.     
  668.     observe: function(subject, topic, data)
  669.     {
  670.         if (topic != "nsPref:changed")
  671.         {
  672.             return;
  673.         }
  674.  
  675.         switch(data)
  676.         {
  677.             case "StartAtBrowserStart":
  678.                 this._StartAtBrowserStart = this.prefs.getBoolPref("StartAtBrowserStart");
  679.                 break;
  680.                 
  681.             case "AlwaysOpenDetached":
  682.                 this._AlwaysOpenDetached = this.prefs.getBoolPref("AlwaysOpenDetached");
  683.                 break;
  684.                 
  685.             case "ShowHttpFoxHelperRequests":
  686.                 this._ShowHttpFoxHelperRequests = this.prefs.getBoolPref("ShowHttpFoxHelperRequests");
  687.                 break;
  688.                 
  689.             case "ColorRequests":
  690.                 this._ColorRequests = this.prefs.getBoolPref("ColorRequests");
  691.                 break;
  692.                 
  693.             case "ShowDebugTab":
  694.                 this._ShowDebugTab = this.prefs.getBoolPref("ShowDebugTab");
  695.                 break;
  696.                 
  697.             case "ForceCaching":
  698.                 this._ForceCaching = this.prefs.getBoolPref("ForceCaching");
  699.                 break;
  700.         }
  701.     },
  702.     
  703.     get StartAtBrowserStart() 
  704.     { 
  705.         return this._StartAtBrowserStart;
  706.     },
  707.     set StartAtBrowserStart(value) 
  708.     {
  709.         this._StartAtBrowserStart = value;
  710.         this.prefs.setCharPref("StartAtBrowserStart", value);
  711.     },
  712.     
  713.     get AlwaysOpenDetached() 
  714.     { 
  715.         return this._AlwaysOpenDetached;
  716.     },
  717.     set AlwaysOpenDetached(value) 
  718.     {
  719.         this._AlwaysOpenDetached = value;
  720.         this.prefs.setIntPref("AlwaysOpenDetached", value);
  721.     },
  722.     
  723.     get ShowHttpFoxHelperRequests() 
  724.     { 
  725.         return this._ShowHttpFoxHelperRequests;
  726.     },
  727.     set ShowHttpFoxHelperRequests(value) 
  728.     {
  729.         this._ShowHttpFoxHelperRequests = value;
  730.         this.prefs.setBoolPref("ShowHttpFoxHelperRequests", value);
  731.     },
  732.     
  733.     get ColorRequests() 
  734.     { 
  735.         return this._ColorRequests;
  736.     },
  737.     set ColorRequests(value) 
  738.     {
  739.         this._ColorRequests = value;
  740.         this.prefs.setBoolPref("ColorRequests", value);
  741.     },
  742.     
  743.     get ShowDebugTab() 
  744.     { 
  745.         return this._ShowDebugTab;
  746.     },
  747.     set ShowDebugTab(value) 
  748.     {
  749.         this._ShowDebugTab = value;
  750.         this.prefs.setBoolPref("ShowDebugTab", value);
  751.     },
  752.     
  753.     get ForceCaching() 
  754.     { 
  755.         return this._ForceCaching;
  756.     },
  757.     set ForceCaching(value) 
  758.     {
  759.         this._ForceCaching = value;
  760.         this.prefs.setBoolPref("ForceCaching", value);
  761.     }
  762. };
  763.  
  764. // ************************************************************************************************
  765.  
  766. // HttpFoxRequest
  767. function HttpFoxRequest(HttpFoxServiceReference, HttpChannelReference, HttpFoxContext, HttpFoxRequestEventReference)
  768. {
  769.     try 
  770.     {
  771.         this.HttpChannel = HttpChannelReference.QueryInterface(Components.interfaces.nsIHttpChannel);
  772.     }
  773.     catch(ex) 
  774.     {
  775.         // discard that non-httpchannel thing
  776.         return
  777.     }
  778.     this.HttpFox = HttpFoxServiceReference;
  779.     this.Context = HttpFoxContext;
  780.     
  781.     this.init(HttpFoxRequestEventReference);
  782. }
  783. HttpFoxRequest.prototype = 
  784. {
  785.     HttpFox: null,
  786.     HttpChannel: null,
  787.     Context: null,
  788.     RequestLog: null,
  789.     EventSource: null,
  790.     EventSourceData: null,
  791.     MasterIndex: null,
  792.     HttpFoxRequestEventSink: null,
  793.     
  794.     // custom request properties
  795.     StartTimestamp: null,
  796.     ResponseStartTimestamp: null,
  797.     EndTimestamp: null,
  798.     Content: null,
  799.     ContentStatus: null,
  800.     BytesLoaded: 0,
  801.     BytesLoadedTotal: 0,
  802.     BytesSent: 0,
  803.     BytesSentTotal: 0,
  804.     ResponseHeadersSize: 0,
  805.     RequestHeadersSize: 0,
  806.     
  807.     // request states
  808.     IsFinished: false,
  809.     IsFinal: false, // last scan and cleanup was done
  810.     IsAborted: false,
  811.     IsLoadingBody: false,
  812.     IsSending: false,
  813.     HasReceivedResponseHeaders: false,
  814.     IsRedirect: false,
  815.     HasErrorCode: false,
  816.     IsError: false,
  817.     IsFromCache: false,
  818.     HasCacheInfo: false,
  819.     //IsContentAvailable: false,
  820.     HasPostData: false, 
  821.     HasQueryStringData: false,
  822.     HasCookieData: false,
  823.     
  824.     // request/response data
  825.     RequestHeaders: null,
  826.     ResponseHeaders: null,
  827.     PostDataHeaders: null,
  828.     PostData: null,
  829.     PostDataParameters: null,
  830.     PostDataMIMEParts: null,
  831.     PostDataMIMEBoundary: null,
  832.     IsPostDataMIME: null,
  833.     PostDataContentLength: null,
  834.     IsPostDataTooBig: false,
  835.     QueryString: null,
  836.     QueryStringParameters: null,
  837.     CookiesSent: null,
  838.     CookiesReceived: null,
  839.     IsBackground: false,
  840.     
  841.     // httpchannel-, request properties
  842.     Status: null,
  843.     Url: null,
  844.     URIPath: null,
  845.     URIScheme: null,
  846.     RequestProtocolVersion: null,
  847.     RequestMethod: null,
  848.     ResponseProtocolVersion: null,
  849.     ResponseStatus: null,
  850.     ResponseStatusText: null,
  851.     ContentType: null,
  852.     ContentCharset: null,
  853.     ContentLength: null,
  854.     LoadFlags: null,
  855.     Name: null,
  856.     RequestSucceeded: null,
  857.     IsNoStoreResponse: null,
  858.     IsNoCacheResponse: null,
  859.     IsFromCache: null,
  860.     CacheToken: null,
  861.     CacheToken_key: null,
  862.     CacheKey: null,
  863.     CacheAsFile: null,
  864.     CacheFile: null,
  865.     Priority: null,
  866.     EntityId: null,
  867.     
  868.     init: function(requestEvent)
  869.     {
  870.         // set current as starttime of request
  871.         this.setStartTimestampNow();
  872.         
  873.         // a new request log
  874.         this.RequestLog = new Array();
  875.  
  876.         // store event sink
  877.         this.HttpFoxRequestEventSink = requestEvent.HttpFoxRequestEventSink;
  878.         
  879.         // update/init from first requestevent
  880.         this.updateFromRequestEvent(requestEvent)
  881.     },
  882.     
  883.     checkRequestState: function()
  884.     {
  885.         // aborted:        
  886.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_STATE_CHANGED
  887.             //&& getStatusTextFromCode(HttpFoxStatusCodeType.WEBPROGRESS_TRANSITION, this.EventSourceData["flags"]) == "STATE_STOP"
  888.             && this.EventSourceData["flags"] & Components.interfaces.nsIWebProgressListener.STATE_STOP
  889.             && this.EventSourceData["status"] == utils.HttpFoxNsResultErrors.NS_BINDING_ABORTED)
  890.         {
  891.             // aborted
  892.             this.setAborted();
  893.             return;
  894.         }
  895.         
  896.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_STATE_CHANGED
  897.             && this.EventSourceData["flags"] & Components.interfaces.nsIWebProgressListener.STATE_STOP) 
  898.         {
  899.             // all finished
  900.             this.setFinished();
  901.             return;
  902.         }
  903.         
  904.         if (this.IsBackground && this.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE)
  905.         {
  906.             this.setFinished();
  907.             return;
  908.         }
  909.         
  910.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_MERGED_RESPONSE)
  911.         {
  912.             // got 304 and got content from cache
  913.             this.setFinished();
  914.             this.HasCacheInfo = true;
  915.             this.BytesLoaded = this.BytesLoadedTotal = this.HttpChannel.contentLength;
  916.             return;
  917.         }
  918.  
  919.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE
  920.             && (this.ResponseStatus != 200))
  921.         {
  922.             this.setFinished();
  923.             return;
  924.         }
  925.         
  926.         if (this.BytesLoadedTotal > 0 && this.BytesLoaded >= this.BytesLoadedTotal)
  927.         {
  928.             this.setFinished();
  929.             return;
  930.         }
  931.         
  932.         if (this.BytesLoadedTotal == -1 && this.ContentLength != null)
  933.         {
  934.             this.setFinished();
  935.             return;
  936.         }
  937.         
  938.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_STATE_CHANGED
  939.             && (this.EventSourceData["flags"] & Components.interfaces.nsIWebProgressListener.STATE_REDIRECTING)) 
  940.         {
  941.             this.ResponseStatus = this.HttpChannel.responseStatus;
  942.             this.setFinished();
  943.             // TODO: only if there wasn't a 302 already. so move to "are we finished code"
  944.             // TODO: set 301, read from an cache entry. directly... to get 301 target url
  945.             return;
  946.         }
  947.         
  948.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE
  949.             && this.ContentLength != null && (this.ContentLength == 0 || this.ContentLength == -1))
  950.         {
  951.             // 0 = no content. finished.
  952.             this.setFinished();
  953.             return;
  954.         }
  955.     },
  956.     
  957.     updateFromRequestEvent: function(requestEvent)
  958.     {
  959.         try
  960.         {
  961.         // check if just a status update
  962.         if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.EVENTSINK_ON_STATUS
  963.             || requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_STATUS_CHANGED)
  964.         {
  965.             if ((this.IsLoadingBody || this.IsSending) 
  966.                 && this.RequestLog[this.RequestLog.length - 1].EventSource == this.HttpFox.HttpFoxEventSourceType.EVENTSINK_ON_STATUS
  967.                 //&& (getStatusTextFromCode(HttpFoxStatusCodeType.SOCKETTRANSPORT, requestEvent.EventSourceData["status"]) == "STATUS_RECEIVING_FROM"
  968.                 && (requestEvent.EventSourceData["status"] == Components.interfaces.nsISocketTransport.STATUS_RECEIVING_FROM
  969.                     || requestEvent.EventSourceData["status"] == Components.interfaces.nsISocketTransport.STATUS_SENDING_TO))
  970.                     //|| getStatusTextFromCode(HttpFoxStatusCodeType.SOCKETTRANSPORT, requestEvent.EventSourceData["status"]) == "STATUS_SENDING_TO"))
  971.             {
  972.                 // no need for multiple loading status change logs. just return
  973.                 return;
  974.             }
  975.         }
  976.         
  977.         // check if just a progress update
  978.         if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.EVENTSINK_ON_PROGRESS
  979.             || requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_PROGRESS_CHANGED)
  980.         {
  981.             if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.EVENTSINK_ON_PROGRESS)
  982.             {
  983.                 var progress = requestEvent.EventSourceData["progress"];
  984.                 var progressMax = requestEvent.EventSourceData["progressMax"];
  985.             }
  986.             else if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_PROGRESS_CHANGED)
  987.             {
  988.                 var progress = requestEvent.EventSourceData["curSelfProgress"];
  989.                 var progressMax = requestEvent.EventSourceData["maxSelfProgress"];
  990.             }
  991.         
  992.             if (this.IsLoadingBody || this.IsSending)
  993.             {
  994.                 if (progress < progressMax)
  995.                 {
  996.                     if (this.IsSending)
  997.                     {
  998.                         // just update progress size and return
  999.                         this.BytesSent = progress;
  1000.                         this.BytesSentTotal = progressMax;
  1001.                     }
  1002.                     else
  1003.                     {
  1004.                         // just update progress size and return
  1005.                         this.BytesLoaded = progress;
  1006.                         this.BytesLoadedTotal = progressMax;    
  1007.                     }
  1008.                 
  1009.                     return;
  1010.                 }
  1011.             }
  1012.             else if (!this.IsFinished)
  1013.             {
  1014.                 // first load progress. store it
  1015.                 this.IsLoadingBody = true;
  1016.             }
  1017.         }
  1018.         
  1019.         // update the properties
  1020.         this.adjustDataFromRequestEvent(requestEvent);
  1021.         
  1022.         // log the requestevent
  1023.         this.logEvent(new HttpFoxRequestLogData(requestEvent));
  1024.  
  1025.         // update request states
  1026.         this.checkRequestState();
  1027.         }
  1028.         catch(e)
  1029.         {
  1030.             dump("\ne: " + e);
  1031.         }
  1032.     },
  1033.     
  1034.     adjustDataFromRequestEvent: function(requestEvent)
  1035.     {
  1036.         this.EventSource = requestEvent.EventSource;
  1037.         this.EventSourceData = requestEvent.EventSourceData;
  1038.         
  1039.         if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_MODIFY_REQUEST)
  1040.         {
  1041.             // start sending
  1042.             this.IsSending = true;
  1043.         }
  1044.         
  1045.         if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE)
  1046.         {
  1047.             // start receiving
  1048.             this.IsSending = false;
  1049.             this.HasReceivedResponseHeaders = true;
  1050.             this.ResponseStartTimestamp = (new Date()).getTime();
  1051.         }
  1052.         
  1053.         if (this.Url == null)
  1054.         {
  1055.             this.Url = requestEvent.Url;
  1056.         }
  1057.         
  1058.         if (this.URIPath == null)
  1059.         {
  1060.             this.URIPath = requestEvent.URIPath;
  1061.         }
  1062.         
  1063.         if (this.URIScheme == null)
  1064.         {
  1065.             this.URIScheme = requestEvent.URIScheme;
  1066.         }
  1067.  
  1068.         if (this.RequestProtocolVersion == null)
  1069.         {
  1070.             this.RequestProtocolVersion = requestEvent.RequestProtocolVersion;
  1071.         }
  1072.         
  1073.         if (this.RequestMethod == null)
  1074.         {
  1075.             this.RequestMethod = requestEvent.RequestMethod;
  1076.         }
  1077.         
  1078.         if (this.ResponseProtocolVersion == null)
  1079.         {
  1080.             this.ResponseProtocolVersion = requestEvent.ResponseProtocolVersion;
  1081.         }
  1082.         
  1083.         if (requestEvent.ResponseStatus != null 
  1084.             && this.ResponseStatus != requestEvent.ResponseStatus
  1085.             && this.ResponseStatus != 304)
  1086.         {
  1087.             this.ResponseStatus = requestEvent.ResponseStatus;
  1088.             this.ResponseStatusText = requestEvent.ResponseStatusText;
  1089.         }
  1090.         
  1091.         if (requestEvent.Context != null) 
  1092.         {
  1093.             this.Context = requestEvent.Context;
  1094.         }
  1095.         
  1096.         if (this.LoadFlags == null)
  1097.         {
  1098.             this.LoadFlags = requestEvent.LoadFlags;
  1099.         }
  1100.         
  1101.         if (this.Status == null)
  1102.         {
  1103.             this.Status = requestEvent.Status;
  1104.         }
  1105.         
  1106.         if (this.Name == null)
  1107.         {
  1108.             this.Name = requestEvent.Name;
  1109.         }
  1110.  
  1111.         if (this.RequestSucceeded == null)
  1112.         {
  1113.             this.RequestSucceeded = requestEvent.RequestSucceeded;
  1114.         }
  1115.  
  1116.         
  1117.         if ((this.ContentType == null || this.ContentType == "application/x-unknown-content-type")
  1118.             && requestEvent.ContentType != null)
  1119.         {
  1120.             this.ContentType = requestEvent.ContentType;
  1121.         }
  1122.  
  1123.         if (this.ContentCharset == null)
  1124.         {
  1125.             this.ContentCharset = requestEvent.ContentCharset;
  1126.         }
  1127.  
  1128.         if (requestEvent.ContentLength != null && this.ContentLength != requestEvent.ContentLength)
  1129.         {
  1130.             this.ContentLength = requestEvent.ContentLength;
  1131.         }
  1132.         
  1133.         if (this.RequestSucceeded == null)
  1134.         {
  1135.             this.RequestSucceeded = requestEvent.RequestSucceeded;
  1136.         }
  1137.         
  1138.         if (this.IsNoStoreResponse == null)
  1139.         {
  1140.             this.IsNoStoreResponse = requestEvent.IsNoStoreResponse;
  1141.         }
  1142.         
  1143.         if (this.IsNoCacheResponse == null)
  1144.         {
  1145.             this.IsNoCacheResponse = requestEvent.IsNoCacheResponse;
  1146.         }
  1147.         
  1148.         if (this.EntityId == null)
  1149.         {
  1150.             this.EntityId = requestEvent.EntityId;
  1151.         }
  1152.         
  1153.         if (this.Priority == null)
  1154.         {
  1155.             this.Priority = requestEvent.Priority;
  1156.         }
  1157.  
  1158.         // cache info stuff
  1159.         if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.SCANNED_COMPLETE
  1160.             && !this.HasReceivedResponseHeaders
  1161.             && this.ResponseStatus == 200)
  1162.         {
  1163.             this.IsFromCache = true;
  1164.         }
  1165.         
  1166.         if (this.IsFromCache != true && requestEvent.IsFromCache != null)
  1167.         {
  1168.             this.IsFromCache = requestEvent.IsFromCache;
  1169.         }
  1170.     
  1171.         if (this.HasCacheInfo != true && requestEvent.HasCacheInfo)
  1172.         {
  1173.             this.HasCacheInfo = requestEvent.HasCacheInfo;
  1174.         }
  1175.         if (requestEvent.HasCacheInfo)
  1176.         {
  1177.             if (this.CacheToken == null)
  1178.             {
  1179.                 this.CacheToken = requestEvent.CacheToken;
  1180.             }
  1181.             if (this.CacheKey == null)
  1182.             {
  1183.                 this.CacheKey = requestEvent.CacheKey;
  1184.             }
  1185.             if (this.ContentCharset == null)
  1186.             {
  1187.                 this.ContentCharset = requestEvent.ContentCharset;
  1188.             }
  1189.             if (this.ContentCharset == null)
  1190.             {
  1191.                 this.ContentCharset = requestEvent.ContentCharset;
  1192.             }
  1193.         }
  1194.         
  1195.         if (this.CacheToken_key == null && requestEvent.CacheToken_key != null)
  1196.         {
  1197.             this.CacheToken_key = requestEvent.CacheToken_key;
  1198.         }
  1199.         if (requestEvent.CacheToken_clientID != null)
  1200.         {
  1201.             this.CacheToken_clientID = requestEvent.CacheToken_clientID;
  1202.         }
  1203.         if (requestEvent.CacheKey != null)
  1204.         {
  1205.             this.CacheKey = requestEvent.CacheKey;
  1206.             //alert('token key: ' + this.CacheKey);
  1207.         }
  1208.         
  1209.         // custom properties
  1210.         if (requestEvent.RequestHeaders != null)
  1211.         {
  1212.             this.RequestHeaders = requestEvent.RequestHeaders;
  1213.         }
  1214.  
  1215.         if (requestEvent.ResponseHeaders != null)
  1216.         {
  1217.             this.ResponseHeaders = requestEvent.ResponseHeaders;
  1218.         }
  1219.  
  1220.         if (requestEvent.CookiesSent != null)
  1221.         {
  1222.             this.CookiesSent = requestEvent.CookiesSent;
  1223.         }
  1224.         
  1225.         if (requestEvent.CookiesReceived != null)
  1226.         {
  1227.             this.CookiesReceived = requestEvent.CookiesReceived;
  1228.         }
  1229.  
  1230.         // POST data
  1231.         if (requestEvent.PostDataHeaders != null)
  1232.         {
  1233.             this.PostDataHeaders = requestEvent.PostDataHeaders;
  1234.         }
  1235.  
  1236.         if (requestEvent.PostData != null)
  1237.         {
  1238.             this.PostData = requestEvent.PostData;
  1239.         }
  1240.  
  1241.         if (requestEvent.PostDataParameters != null)
  1242.         {
  1243.             this.PostDataParameters = requestEvent.PostDataParameters;
  1244.         }
  1245.  
  1246.         if (requestEvent.PostDataMIMEParts != null)
  1247.         {
  1248.             this.PostDataMIMEParts = requestEvent.PostDataMIMEParts;
  1249.         }
  1250.  
  1251.         if (requestEvent.IsPostDataMIME != null)
  1252.         {
  1253.             this.IsPostDataMIME = requestEvent.IsPostDataMIME;
  1254.         }
  1255.  
  1256.         if (requestEvent.PostDataMIMEBoundary != null)
  1257.         {
  1258.             this.PostDataMIMEBoundary = requestEvent.PostDataMIMEBoundary;
  1259.         }
  1260.         
  1261.         if (requestEvent.IsPostDataTooBig != null)
  1262.         {
  1263.             this.IsPostDataTooBig = requestEvent.IsPostDataTooBig;
  1264.         }
  1265.         
  1266.         //QueryString: null,
  1267.         if (requestEvent.QueryString != null)
  1268.         {
  1269.             this.QueryString = requestEvent.QueryString;
  1270.         }
  1271.         //QueryStringParameters: null,
  1272.         if (requestEvent.QueryStringParameters != null)
  1273.         {
  1274.             this.QueryStringParameters = requestEvent.QueryStringParameters;
  1275.         }
  1276.         //IsBackground: false,
  1277.         if (requestEvent.IsBackground != null)
  1278.         {
  1279.             this.IsBackground = requestEvent.IsBackground;
  1280.         }
  1281.         
  1282.         if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_MODIFY_REQUEST)
  1283.         {
  1284.             // calc header size
  1285.             this.RequestHeadersSize = this.calcRequestHeadersSize(requestEvent);
  1286.             this.getRequestContentLength(requestEvent);
  1287.         }
  1288.         
  1289.         if (requestEvent.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE)
  1290.         {
  1291.             // calc header size
  1292.             this.RequestHeadersSize = this.calcRequestHeadersSize(this);
  1293.             this.ResponseHeadersSize = this.calcResponseHeadersSize(requestEvent);
  1294.         }
  1295.         
  1296.         // update bytes loaded/total
  1297.         // BytesLoaded: 0,
  1298.         if (this.IsSending) 
  1299.         {
  1300.             if (this.BytesSent < requestEvent.progress)
  1301.             {
  1302.                 this.BytesSent = requestEvent.progress;
  1303.             }
  1304.  
  1305.             // take sent total from contentlength
  1306.             this.BytesSentTotal = (this.PostDataContentLength ? this.PostDataContentLength : 0) + this.RequestHeadersSize;
  1307.         }
  1308.         else
  1309.         {
  1310.             if (this.BytesLoaded < requestEvent.progress)
  1311.             {
  1312.                 this.BytesLoaded = requestEvent.progress;
  1313.             }
  1314.             // BytesLoadedTotal: 0,
  1315.             if (this.BytesLoadedTotal < requestEvent.progressMax)
  1316.             {
  1317.                 this.BytesLoadedTotal = requestEvent.progressMax;
  1318.             }
  1319.         }
  1320.         
  1321.         // if no info on bytes loaded, just use the contentLength value
  1322.         if (this.IsFinished 
  1323.             && (this.BytesLoaded == 0 || this.BytesLoaded == -1) 
  1324.             && this.ContentLength != -1)
  1325.         {
  1326.             this.BytesLoaded = this.ContentLength;
  1327.         }
  1328.         
  1329.     },
  1330.     
  1331.     getRequestContentLength: function(requestEvent)
  1332.     {
  1333.         for (var i in requestEvent.PostDataHeaders)
  1334.         {
  1335.             if (i.toLowerCase() == "content-length")
  1336.             {
  1337.                 this.PostDataContentLength = parseInt(requestEvent.PostDataHeaders[i]);
  1338.                 return;
  1339.             }
  1340.         }
  1341.         
  1342.         for (var i in requestEvent.RequestHeaders)
  1343.         {
  1344.             if (i.toLowerCase() == "content-length")
  1345.             {
  1346.                 this.PostDataContentLength = parseInt(requestEvent.RequestHeaders[i]);
  1347.                 return;
  1348.             }
  1349.         }
  1350.     },
  1351.     
  1352.     calcRequestHeadersSize: function(requestEvent)
  1353.     {
  1354.         var byteString = "";
  1355.         byteString += requestEvent.RequestMethod + " " + requestEvent.URIPath + " HTTP/" + requestEvent.RequestProtocolVersion + "\r\n";
  1356.         
  1357.         for (var i in requestEvent.RequestHeaders)
  1358.         {
  1359.             byteString += i + ": " + requestEvent.RequestHeaders[i] + "\r\n";
  1360.         }
  1361.         
  1362.         for (var i in requestEvent.PostDataHeaders)
  1363.         {
  1364.             byteString += i + ": " + requestEvent.PostDataHeaders[i] + "\r\n";
  1365.         }
  1366.         
  1367.         byteString += "\r\n";
  1368.         
  1369.         return byteString.length;
  1370.     },
  1371.     
  1372.     calcResponseHeadersSize: function(requestEvent)
  1373.     {
  1374.         var byteString = "";
  1375.         byteString += "HTTP/" + requestEvent.ResponseProtocolVersion + " " + requestEvent.ResponseStatus + " " + requestEvent.ResponseStatusText + "\r\n";
  1376.         
  1377.         for (var i in requestEvent.ResponseHeaders)
  1378.         {
  1379.             byteString += i + ": " + requestEvent.RequestHeaders[i] + "\r\n";
  1380.         }
  1381.         
  1382.         byteString += "\r\n";
  1383.         
  1384.         return byteString.length;
  1385.     },
  1386.     
  1387.     //M -> provide callback
  1388.     startGetRawContent: function(callback)
  1389.     {
  1390.         this.CallbackController = callback;
  1391.         
  1392.         if (this.Content != null && this.ContentStatus != null) 
  1393.         {
  1394.             this.CallbackController.showRawContent(this.ContentStatus);
  1395.             return;
  1396.         }
  1397.         
  1398.         if (this.Context != null) {
  1399.             //TODO: CHECK IF CACHEKEY_AFTER EXISTS
  1400.             if (!this.CacheKey_After)
  1401.             {
  1402.                 //not ready
  1403.                 //this.Content = "not ready";
  1404.                 this.CallbackController.showRawContent(-1);
  1405.                 return;
  1406.             }
  1407.             
  1408.             this.Context.sourceCache.loadData(this.Url, this.PostData, this.CacheKey_After, this);
  1409.         }
  1410.     },
  1411.     
  1412.     //M -> use callback
  1413.     endGetRawContent: function(data, status)
  1414.     {
  1415.         this.Content = data;
  1416.         this.ContentStatus = status;
  1417.         this.CallbackController.showRawContent(status);
  1418.     },
  1419.     
  1420.     //M
  1421.     showCacheInfo: function() 
  1422.     {
  1423.         if (!this.HasCacheInfo) 
  1424.         {
  1425.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "(none)", "(This request was not served from cache)");
  1426.             return;
  1427.         }
  1428.     
  1429.         try 
  1430.         {
  1431.             var CacheInfo = this.CacheToken.QueryInterface(Components.interfaces.nsICacheEntryInfo);
  1432.             
  1433.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Key", CacheInfo.key);
  1434.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Expires", utils.formatDateTime(CacheInfo.expirationTime));
  1435.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Hit Count", CacheInfo.fetchCount);
  1436.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Last Hit", utils.formatDateTime(CacheInfo.lastFetched));
  1437.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Last Modification", utils.formatDateTime(CacheInfo.lastModified));
  1438.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Client ID", CacheInfo.clientID);
  1439.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Device ID", CacheInfo.deviceID);
  1440.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Size", CacheInfo.dataSize);
  1441.             
  1442.             if (this.CacheFile != null) 
  1443.             {
  1444.                 var CacheFileInfo = this.CacheFile.QueryInterface(Components.interfaces.nsIFile);
  1445.                 
  1446.                 this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Filename", CacheFileInfo.leafName);
  1447.                 this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Filepath", CacheFileInfo.target);
  1448.                 this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Filesize", CacheFileInfo.fileSize);
  1449.                 this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "File Last Modification", utils.formatDateTime(CacheFileInfo.lastModifiedTime / 1000));
  1450.             }
  1451.             else
  1452.             {
  1453.                 this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "Filename", "n/a");
  1454.             }
  1455.         } 
  1456.         catch (ex)
  1457.         {
  1458.             this.HttpFox.addHeaderRow("hf_CacheInfoChildren", "(error)", "(There was an error accessing the cache information)");
  1459.         }
  1460.     },
  1461.         
  1462.     setFinished: function()
  1463.     {
  1464.         this.IsFinished = true;
  1465.         if (!this.EndTimestamp)
  1466.         {
  1467.             this.setEndTimestampNow();    
  1468.         }
  1469.     },
  1470.     
  1471.     setAborted: function()
  1472.     {
  1473.         this.IsAborted = true;
  1474.         this.IsFinished = true;
  1475.         this.setEndTimestampNow();
  1476.     },
  1477.     
  1478.     setStartTimestampNow: function()
  1479.     {
  1480.         this.StartTimestamp = (new Date()).getTime();
  1481.     },
  1482.     
  1483.     setEndTimestampNow: function()
  1484.     {
  1485.         this.EndTimestamp = (new Date()).getTime();
  1486.     },
  1487.     
  1488.     logEvent: function(logdata)
  1489.     {
  1490.         this.RequestLog.push(logdata);
  1491.     },
  1492.     
  1493.     getBytesLoaded: function()
  1494.     {
  1495.         if (this.RequestMethod == "HEAD")
  1496.         {
  1497.             return this.ResponseHeadersSize;
  1498.         }
  1499.         
  1500.         return this.ResponseHeadersSize + this.BytesLoaded;
  1501.     },
  1502.     
  1503.     getBytesLoadedTotal: function()
  1504.     {
  1505.         if (this.RequestMethod == "HEAD")
  1506.         {
  1507.             return this.ResponseHeadersSize;
  1508.         }
  1509.         
  1510.         return this.ResponseHeadersSize + this.BytesLoadedTotal;
  1511.     },
  1512.     
  1513.     getBytesSent: function()
  1514.     {
  1515.         return this.RequestHeadersSize + this.BytesSent;
  1516.     },
  1517.     
  1518.     getBytesSentTotal: function()
  1519.     {
  1520.         return this.RequestHeadersSize + this.PostDataContentLength;
  1521.     },
  1522.     
  1523.     complete: function()
  1524.     {
  1525.         this.IsFinal = true;
  1526.         
  1527.         this.IsSending = false;
  1528.         
  1529.         this.setFinished();
  1530.         
  1531.         try 
  1532.         {
  1533.             this.Status = this.HttpChannel.status;
  1534.             this.CacheKey_After = this.HttpChannel.cacheKey;
  1535.         }
  1536.         catch(exc) 
  1537.         {
  1538.         }
  1539.         
  1540.         if (this.Status == utils.HttpFoxNsResultErrors.NS_BINDING_ABORTED)
  1541.         //if (this.Status != 0)
  1542.         {
  1543.             // aborted
  1544.             this.setAborted();
  1545.             //return;
  1546.         }
  1547.         
  1548.         this.updateFromRequestEvent(
  1549.             new HttpFoxRequestEvent(
  1550.                 this.HttpFox, 
  1551.                 this.HttpChannel, 
  1552.                 this.HttpFox.HttpFoxEventSourceType.SCANNED_COMPLETE, 
  1553.                 null, 
  1554.                 utils.getContextFromRequest(this.HttpChannel)));
  1555.         
  1556.         try {
  1557.             // release httpchannel, listeners and context
  1558.             if (this.HttpChannel.loadGroup && this.HttpChannel.loadGroup.groupObserver) {
  1559.                 var go = HttpChannel.loadGroup.groupObserver;
  1560.                 go.QueryInterface(Components.interfaces.nsIWebProgress);
  1561.                 try 
  1562.                 {
  1563.                     go.removeProgressListener(this.HttpFox.Observer);
  1564.                 }
  1565.                 catch(ex) 
  1566.                 {}
  1567.             }
  1568.             
  1569.             this.HttpFoxRequestEventSink.HttpChannel.notificationCallbacks = this.HttpFoxRequestEventSink.OriginalNotificationCallbacks;
  1570.             this.HttpFoxRequestEventSink = null;
  1571.             this.HttpChannel = null;
  1572.             
  1573.         }
  1574.         catch(e)
  1575.         {
  1576.             //dump("\nexc: " + e);
  1577.         }
  1578.         
  1579.         return;
  1580.     },
  1581.  
  1582.     isContentAvailable : function() 
  1583.     {
  1584.         if (this.isRedirect())
  1585.             //|| this.isError()
  1586.             //|| this.IsAborted)
  1587.         {
  1588.             return false;
  1589.         }
  1590.         
  1591.         if (this.RequestMethod == "HEAD")
  1592.         {
  1593.             return false;
  1594.         }
  1595.         
  1596.         return true;
  1597.     },
  1598.    
  1599.     hasErrorCode : function() 
  1600.     {
  1601.         if (this.Status && !this.isRedirect())
  1602.         {
  1603.             return true;
  1604.         }
  1605.         
  1606.         return false;
  1607.     },
  1608.     
  1609.     isRedirect : function()
  1610.     {
  1611.         if (this.Status && this.Status == utils.HttpFoxNsResultErrors.NS_BINDING_REDIRECTED) 
  1612.         {
  1613.             return true;
  1614.         }
  1615.         
  1616.         return false;
  1617.     },
  1618.     
  1619.     isError : function()
  1620.     {
  1621.         if (this.IsFinished && this.hasErrorCode() && !this.ResponseStatus)
  1622.         {
  1623.             return true;
  1624.         }
  1625.         
  1626.         return false;
  1627.     },
  1628.     
  1629.     isHTTPS : function()
  1630.     {
  1631.         if (this.URIScheme == "https")
  1632.         {
  1633.             return true;
  1634.         }
  1635.         
  1636.         return false;
  1637.     }
  1638.  
  1639. }
  1640. // ************************************************************************************************
  1641.  
  1642. // HttpFoxRequestEvent
  1643. function HttpFoxRequestEvent(HttpFoxReference, HttpChannelReference, EventSourceType, EventSourceMiscData, HttpFoxContext)
  1644. {
  1645.     try 
  1646.     {
  1647.         this.HttpChannel = HttpChannelReference.QueryInterface(Components.interfaces.nsIHttpChannel);
  1648.     }
  1649.     catch(ex) 
  1650.     {
  1651.         // discard that non-httpchannel thing
  1652.         return
  1653.     }
  1654.     
  1655.     this.HttpFox = HttpFoxReference;
  1656.     this.EventSource = EventSourceType;
  1657.     this.EventSourceData = EventSourceMiscData;
  1658.     this.Context = HttpFoxContext;
  1659.     
  1660.     this.init();
  1661. }
  1662. HttpFoxRequestEvent.prototype = 
  1663. {
  1664.     HttpFox: null, // reference
  1665.     HttpChannel: null, // reference
  1666.     EventSource: null,
  1667.     EventSourceData: null,
  1668.     Context: null, // reference
  1669.     HttpFoxRequestEventSink: null,
  1670.  
  1671.     // custom request properties
  1672.     BytesLoaded: 0,
  1673.     BytesLoadedTotal: 0,
  1674.     Timestamp: null,
  1675.     HasCacheInfo: false,
  1676.     
  1677.     // request/response data
  1678.     RequestHeaders: null,
  1679.     ResponseHeaders: null,
  1680.     PostDataHeaders: null,
  1681.     PostData: null,
  1682.     PostDataParameters: null,
  1683.     IsPostDataMIME: null,
  1684.     PostDataMIMEBoundary: null,
  1685.     PostDataMIMEParts: null,
  1686.     IsPostDataTooBig: false,
  1687.     QueryString: null,
  1688.     QueryStringParameters: null,
  1689.     CookiesSent: null,
  1690.     CookiesReceived: null,
  1691.     IsBackground: false, //?
  1692.     
  1693.     // httpchannel-, request properties
  1694.     Status: null,
  1695.     Url: null,
  1696.     URIPath: null,
  1697.     URIScheme: null,
  1698.     RequestProtocolVersion: null,
  1699.     RequestMethod: null,
  1700.     ResponseProtocolVersion: null,
  1701.     ResponseStatus: null,
  1702.     ResponseStatusText: null,
  1703.     ContentType: null,
  1704.     ContentCharset: null,
  1705.     ContentLength: null,
  1706.     LoadFlags: null,
  1707.     Name: null,
  1708.     RequestSucceeded: null,
  1709.     IsNoStoreResponse: null,
  1710.     IsNoCacheResponse: null,
  1711.     IsFromCache: null,
  1712.     CacheToken: null,
  1713.     CacheToken_key: null,
  1714.     CacheKey: null,
  1715.     CacheAsFile: null,
  1716.     CacheFile: null,
  1717.     Priority: null,
  1718.     IsPending: null,
  1719.     EntityId: null,
  1720.     
  1721.     init: function()
  1722.     {
  1723.         this.Timestamp = (new Date()).getTime();
  1724.         
  1725.         // get properties from httpchannel/request object
  1726.         this.Status = this.HttpChannel.status ? this.HttpChannel.status : null;
  1727.         this.Url = this.HttpChannel.URI ? this.HttpChannel.URI.asciiSpec : null;
  1728.         this.URIScheme = this.HttpChannel.URI ? this.HttpChannel.URI.scheme : null;
  1729.         this.URIPath = this.HttpChannel.URI ? this.HttpChannel.URI.path : null;
  1730.         this.Name = this.HttpChannel.name ? this.HttpChannel.name : null;
  1731.         this.RequestMethod = this.HttpChannel.requestMethod ? this.HttpChannel.requestMethod : null;
  1732.         this.IsPending = this.HttpChannel.isPending();
  1733.         this.LoadFlags = this.HttpChannel.loadFlags;
  1734.         this.Priority = this.HttpChannel.priority ? this.HttpChannel.priority : null;
  1735.         this.IsBackground = this.LoadFlags & Components.interfaces.nsIRequest.LOAD_BACKGROUND;
  1736.  
  1737.         // cache infos
  1738.         //TODO: CLEAN UP
  1739.         this.getCacheInfos();
  1740.         
  1741.         // get response related infos
  1742.         try { this.ContentType = this.HttpChannel.contentType; } catch(ex) {}
  1743.         try { this.ContentCharset = this.HttpChannel.ContentCharset; } catch(ex) {}
  1744.         try { this.ContentLength = this.HttpChannel.contentLength; } catch(ex) {}
  1745.         try { this.RequestSucceeded = this.HttpChannel.requestSucceeded; } catch(ex) {}
  1746.         try { this.ResponseStatus = this.HttpChannel.responseStatus; } catch(ex) {}
  1747.         try { this.ResponseStatusText = this.HttpChannel.responseStatusText; } catch(ex) {}
  1748.         try { this.IsNoStoreResponse = this.HttpChannel.isNoStoreResponse(); } catch(ex) {}
  1749.         try { this.IsNoCacheResponse = this.HttpChannel.isNoCacheResponse(); } catch(ex) {}
  1750.         try { this.EntityId = this.HttpChannel.EntityId; } catch(ex) {}
  1751.         
  1752.         // event specific infos
  1753.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_MODIFY_REQUEST)
  1754.         {
  1755.             // Get Request Headers
  1756.             var dummyHeaderInfo = new HttpFoxHeaderInfo();
  1757.             this.HttpChannel.visitRequestHeaders(dummyHeaderInfo);
  1758.             this.RequestHeaders = dummyHeaderInfo.Headers;
  1759.             
  1760.             // Get QueryString if there.
  1761.             this.getQueryString();
  1762.             
  1763.             // Get Cookie Sent Infos
  1764.             this.getCookiesSent();
  1765.             
  1766.             // Get post data if there.
  1767.             this.getPostData();
  1768.             
  1769.             // Get request protocol version
  1770.             this.getRequestProtocolVersion();
  1771.         }
  1772.         
  1773.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE)
  1774.         {
  1775.             // ok. received a server response.
  1776.             // Get Request Headers again. maybe be changed after us. (e.g. cache-control)
  1777.             var dummyHeaderInfo = new HttpFoxHeaderInfo();
  1778.             this.HttpChannel.visitRequestHeaders(dummyHeaderInfo);
  1779.             this.RequestHeaders = dummyHeaderInfo.Headers;
  1780.  
  1781.             // Get Response Headers
  1782.             var dummyHeaderInfo = new HttpFoxHeaderInfo();
  1783.             this.HttpChannel.visitResponseHeaders(dummyHeaderInfo);
  1784.             this.ResponseHeaders = dummyHeaderInfo.Headers;
  1785.             
  1786.             // Get Cookies Received Infos
  1787.             this.getCookiesReceived();
  1788.             
  1789.             // Get response protocol version
  1790.             this.getResponseProtocolVersion();
  1791.         }
  1792.         
  1793.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.EVENTSINK_ON_PROGRESS)
  1794.         {
  1795.             // update byte count
  1796.             this.BytesLoaded = this.EventSourceData["progress"];
  1797.             this.BytesLoadedTotal = this.EventSourceData["progressMax"];
  1798.         }
  1799.         
  1800.         if (this.EventSource == this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_PROGRESS_CHANGED)
  1801.         {
  1802.             // update byte count
  1803.             this.BytesLoaded = this.EventSourceData["curSelfProgress"];
  1804.             this.BytesLoadedTotal = this.EventSourceData["maxSelfProgress"];
  1805.         }
  1806.     },
  1807.     
  1808.     getRequestProtocolVersion: function()
  1809.     {
  1810.         try 
  1811.         {
  1812.             var httpChannelInternal = this.HttpChannel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
  1813.             var ver1 = new Object;
  1814.             var ver2 = new Object;
  1815.             httpChannelInternal.getRequestVersion(ver1, ver2);
  1816.             this.RequestProtocolVersion = ver1.value + "." + ver2.value;
  1817.         }
  1818.         catch(ex)
  1819.         {
  1820.             return;
  1821.         }
  1822.     },
  1823.     
  1824.     getResponseProtocolVersion: function()
  1825.     {
  1826.         try 
  1827.         {
  1828.             var httpChannelInternal = this.HttpChannel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
  1829.             var ver1 = new Object;
  1830.             var ver2 = new Object;
  1831.             httpChannelInternal.getResponseVersion(ver1, ver2);
  1832.             this.ResponseProtocolVersion = ver1.value + "." + ver2.value;
  1833.         }
  1834.         catch(ex)
  1835.         {
  1836.             return;
  1837.         }
  1838.     },
  1839.     
  1840.     getCacheInfos: function()
  1841.     {
  1842.         // cache infos
  1843.         if (this.HttpChannel instanceof Components.interfaces.nsICachingChannel) 
  1844.         {
  1845.             this.HttpChannel.QueryInterface(Components.interfaces.nsICachingChannel);
  1846.         }
  1847.         else
  1848.         {
  1849.             return;
  1850.         }
  1851.         
  1852.         try {
  1853.             this.IsFromCache = this.HttpChannel.isFromCache();
  1854.         }
  1855.         catch(ex) 
  1856.         {
  1857.             this.IsFromCache = false;
  1858.         }
  1859.  
  1860.         /*
  1861.         //if (this.IsFromCache)
  1862.         //{
  1863.             try 
  1864.             {
  1865.                 var CacheInfo = this.HttpChannel.cacheToken.QueryInterface(Components.interfaces.nsICacheEntryInfo);
  1866.                 if (CacheInfo instanceof Components.interfaces.nsICacheEntryDescriptor)
  1867.                 {
  1868.                     //this.CacheToken = this.HttpChannel.cacheToken;
  1869.                     this.CacheToken_clientID = CacheInfo.clientID;
  1870.                     this.CacheToken_key = CacheInfo.key;
  1871.                     this.HasCacheInfo = true;
  1872.                     //alert('c_id: ' + CacheInfo.clientID + ' - c key: ' + CacheInfo.key);
  1873.                 }
  1874.             } 
  1875.             catch(ex) {
  1876.                 return;
  1877.             }
  1878.         if (this.IsFromCache)
  1879.         {
  1880.             try 
  1881.             {
  1882.                 this.CacheKey = this.HttpChannel.cacheKey;
  1883.                 this.HasCacheInfo = true;
  1884.             } 
  1885.             catch(ex) {}
  1886.                 
  1887.             try 
  1888.             {
  1889.                 this.CacheAsFile = this.HttpChannel.cacheAsFile;
  1890.                 this.HasCacheInfo = true;
  1891.             } 
  1892.             catch(ex) {}
  1893.                 
  1894.             try 
  1895.             {
  1896.                 this.CacheFile = this.HttpChannel.cacheFile;
  1897.                 this.HasCacheInfo = true;
  1898.             } 
  1899.             catch(ex) {}
  1900.         }*/
  1901.         /*else 
  1902.         {
  1903.             var token;
  1904.             if (this.HttpChannel instanceof Components.interfaces.nsICachingChannel) 
  1905.             {
  1906.                 try
  1907.                 {
  1908.                     token = this.HttpChannel.cacheToken;
  1909.                     alert('cache token: ' + token);
  1910.                 } catch (ex)
  1911.                 {
  1912.                     alert('exc cache token: ' + ex)
  1913.                 }
  1914.             }
  1915.             else {
  1916.                 //alert('no cache info');
  1917.             }
  1918.         }*/
  1919.     },
  1920.     
  1921.     getPostData: function()
  1922.     {
  1923.         // Get the postData stream from the Http Object 
  1924.         try 
  1925.         {
  1926.             // Must change HttpChannel to UploadChannel to be able to access post data
  1927.             var postChannel = this.HttpChannel.QueryInterface(Components.interfaces.nsIUploadChannel);
  1928.  
  1929.             // Get the post data stream
  1930.             if (postChannel.uploadStream) 
  1931.             {
  1932.                 this.PostDataChannel = postChannel;
  1933.                 var PostDataHandler = new HttpFoxPostDataHandler(this);
  1934.                 PostDataHandler.getPostData();
  1935.             } 
  1936.         } 
  1937.         catch(ex) 
  1938.         {
  1939.         }
  1940.     },
  1941.     
  1942.     getQueryString: function() {
  1943.         if (this.Url.indexOf("?") == -1) 
  1944.         {
  1945.             return;
  1946.         }
  1947.         this.QueryString = this.Url.slice(this.Url.indexOf("?") + 1, this.Url.length);
  1948.         
  1949.         this.QueryStringParameters = new Array();
  1950.         var queryStringParts = this.QueryString.split("&");
  1951.         for (i in queryStringParts)
  1952.         {
  1953.             var nvName = queryStringParts[i].slice(0, queryStringParts[i].indexOf("=") != -1 ? queryStringParts[i].indexOf("=") : queryStringParts[i].length);
  1954.             var nvValue = (queryStringParts[i].indexOf("=") != -1) ? queryStringParts[i].slice(queryStringParts[i].indexOf("=") + 1, queryStringParts[i].length) : "";
  1955.             this.QueryStringParameters.push([nvName, nvValue]);
  1956.         }
  1957.     },
  1958.     
  1959.     getCookiesSent: function() {
  1960.         this.CookiesSent = new Array();
  1961.         
  1962.         var CookiesStored = utils.getStoredCookies(this.RequestHeaders["Host"], this.URIPath);
  1963.         
  1964.         if (this.RequestHeaders["Cookie"]) {
  1965.             var requestCookies = this.RequestHeaders["Cookie"].split("; ");
  1966.             for (i in requestCookies) {
  1967.                 var cName = requestCookies[i].slice(0, requestCookies[i].indexOf("="));
  1968.                 var cValue = requestCookies[i].slice(cName.length + 1);
  1969.                 
  1970.                 var cookieData = new Array();
  1971.                 cookieData["name"] = cName;
  1972.                 cookieData["value"] = cValue;
  1973.                 
  1974.                 for (var i = 0; i < CookiesStored.length; i++)
  1975.                 {
  1976.                     if (CookiesStored[i].name == cName && CookiesStored[i].value == cValue) 
  1977.                     {
  1978.                         cookieData["domain"] = CookiesStored[i].host;
  1979.                         cookieData["expires"] = CookiesStored[i].expires;
  1980.                         cookieData["path"] = CookiesStored[i].path;
  1981.                         CookiesStored.splice(i, 1);
  1982.                         break;
  1983.                     }
  1984.                 }
  1985.                 
  1986.                 this.CookiesSent.push(cookieData);
  1987.             }
  1988.         }
  1989.     },
  1990.     
  1991.     getCookiesReceived: function() {
  1992.         this.CookiesReceived = new Array();
  1993.         
  1994.         if (this.ResponseHeaders["Set-Cookie"]) 
  1995.         {
  1996.             var responseCookies = this.ResponseHeaders["Set-Cookie"].split("\n");
  1997.             for (i in responseCookies) 
  1998.             {
  1999.                 var dataSections = responseCookies[i].split(";");
  2000.                 var cName = dataSections[0].slice(0, dataSections[0].indexOf("="));
  2001.                 var cValue = dataSections[0].slice(cName.length + 1);
  2002.                 var cookieData = new Array();
  2003.                 cookieData["name"] = cName;
  2004.                 cookieData["value"] = cValue;
  2005.                 
  2006.                 // other infos
  2007.                 for (var u = 1; dataSections[u] != null; u++) 
  2008.                 {
  2009.                     var cInfoName = dataSections[u].slice(1, dataSections[u].indexOf("="));
  2010.                     var cInfoValue = dataSections[u].slice(cInfoName.length + 2);
  2011.                     cookieData[cInfoName.toLowerCase()] = cInfoValue;
  2012.                 }
  2013.                 
  2014.                 if (!cookieData["domain"])
  2015.                 {
  2016.                     cookieData["domain"] = this.RequestHeaders["Host"];
  2017.                 }
  2018.                 
  2019.                 if (!cookieData["path"]) 
  2020.                 {
  2021.                     cookieData["path"] = "/";
  2022.                 }
  2023.                 
  2024.                 // check against stored one
  2025.                 var CookiesStored = utils.getStoredCookies(cookieData["domain"], cookieData["path"]);
  2026.                 for (var i = 0; i < CookiesStored.length; i++)
  2027.                 {
  2028.                     if (CookiesStored[i].name == cName && CookiesStored[i].value == cValue && CookiesStored[i].path == cookieData["path"]) 
  2029.                     {
  2030.                         /*if (cookieData["expires"])
  2031.                         {
  2032.                             cookieData["expires"] = CookiesStored[i].expires;    
  2033.                         }*/
  2034.                         
  2035.                         CookiesStored.splice(i, 1);
  2036.                         break;
  2037.                     }
  2038.                 }
  2039.                 
  2040.                 this.CookiesReceived.push(cookieData);
  2041.             }
  2042.         }
  2043.     }
  2044. }
  2045. // ************************************************************************************************
  2046.  
  2047. // HttpFoxRequestEventSink
  2048. function HttpFoxRequestEventSink(HttpFoxReference, HttpChannel)
  2049. {
  2050.     this.init(HttpFoxReference, HttpChannel);
  2051. }
  2052. HttpFoxRequestEventSink.prototype =
  2053. {
  2054.     // Properties
  2055.     HttpFox: null,
  2056.     OriginalNotificationCallbacks: null,
  2057.     
  2058.     // Constructor
  2059.     init: function(HttpFoxReference, HttpChannel) 
  2060.     {
  2061.         this.HttpFox = HttpFoxReference;
  2062.         if (HttpChannel.notificationCallbacks != null) 
  2063.         {
  2064.             this.OriginalNotificationCallbacks = HttpChannel.notificationCallbacks;
  2065.         }
  2066.         HttpChannel.notificationCallbacks = this;
  2067.     },
  2068.     
  2069.     /**
  2070.     * See nsIProgressEventSink
  2071.     */
  2072.     onProgress: function(request, context, progress, progressMax)
  2073.     {
  2074.         var eventSourceData = new Object();
  2075.         eventSourceData["progress"] = progress;
  2076.         eventSourceData["progressMax"] = progressMax;
  2077.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, request, this.HttpFox.HttpFoxEventSourceType.EVENTSINK_ON_PROGRESS, eventSourceData, utils.getContextFromRequest(request)));
  2078.         // forward to possible other notificationCallbacks
  2079.         try {
  2080.             if (this.OriginalNotificationCallbacks != null) 
  2081.             {
  2082.                 var i = this.OriginalNotificationCallbacks.getInterface(Components.interfaces.nsIProgressEventSink);
  2083.                 i.onProgress(request, context, progress, progressMax);
  2084.             }
  2085.         }
  2086.         catch(e) {}
  2087.     }, 
  2088.    
  2089.     onStatus: function(request, context, status, statusArg)
  2090.     {
  2091.         var eventSourceData = new Object();
  2092.         eventSourceData["status"] = status;
  2093.         eventSourceData["statusArg"] = statusArg;
  2094.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, request, this.HttpFox.HttpFoxEventSourceType.EVENTSINK_ON_STATUS, eventSourceData, utils.getContextFromRequest(request)));
  2095.         // forward to possible other notificationCallbacks
  2096.         try {
  2097.             if (this.OriginalNotificationCallbacks != null) 
  2098.             {
  2099.                 var i = this.OriginalNotificationCallbacks.getInterface(Components.interfaces.nsIProgressEventSink);
  2100.                 i.onStatus(request, context, status, statusArg);
  2101.             }
  2102.         }
  2103.         catch(e) {}
  2104.     }, 
  2105.     /************************************************/
  2106.     
  2107.     /**
  2108.     * nsISupports
  2109.     */
  2110.     QueryInterface: function(iid) 
  2111.     {
  2112.         if (!iid.equals(Components.interfaces.nsISupports) &&
  2113.             !iid.equals(Components.interfaces.nsISupportsWeakReference) &&
  2114.             !iid.equals(Components.interfaces.nsIProgressEventSink))
  2115.         {
  2116.             throw Components.results.NS_ERROR_NO_INTERFACE;
  2117.         }
  2118.         
  2119.         return this;
  2120.     },
  2121.     /********************************************/
  2122.     
  2123.     /**
  2124.     * nsIInterfaceRequestor
  2125.     */
  2126.     getInterface: function(iid)
  2127.     {
  2128.         if (iid.equals(Components.interfaces.nsIProgressEventSink))
  2129.         {
  2130.               return this;
  2131.         }
  2132.         
  2133.         try {
  2134.             if (this.OriginalNotificationCallbacks != null) 
  2135.             {
  2136.                 return this.OriginalNotificationCallbacks;
  2137.             }
  2138.         }
  2139.         catch(e) {
  2140.             //dump("brrr: " + e);
  2141.             //dumpall("\n\n\n****EXC OBJECT IS", this.OriginalNotificationCallbacks);
  2142.         }
  2143.         
  2144.         Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
  2145.         return null;
  2146.     }
  2147.     /********************************************/
  2148. }
  2149.  
  2150.  
  2151. // ************************************************************************************************
  2152.  
  2153. // HttpFoxObserver
  2154. function HttpFoxObserver(HttpFoxReference)
  2155. {
  2156.     this.init(HttpFoxReference);
  2157. }
  2158. HttpFoxObserver.prototype =
  2159. {
  2160.     // Properties
  2161.     HttpFox: null,
  2162.     
  2163.     // Constructor
  2164.     init: function(HttpFoxReference) 
  2165.     {
  2166.         this.HttpFox = HttpFoxReference;
  2167.     },
  2168.     
  2169.     // start observing
  2170.     start: function()
  2171.     {
  2172.         this.addListener();
  2173.     },
  2174.     
  2175.     // end observing
  2176.     stop: function()
  2177.     {
  2178.         this.removeListener();
  2179.     },
  2180.     
  2181.     addListener: function()
  2182.     {
  2183.         // Register listeners
  2184.         var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  2185.         observerService.addObserver(this, "http-on-modify-request", false);
  2186.         observerService.addObserver(this, "http-on-examine-response", false);
  2187.         observerService.addObserver(this, "http-on-examine-merged-response", false);
  2188.     },
  2189.     
  2190.     removeListener: function()
  2191.     {
  2192.         // Unregistering listeners
  2193.         var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  2194.         observerService.removeObserver(this, "http-on-modify-request");
  2195.         observerService.removeObserver(this, "http-on-examine-response");
  2196.         observerService.removeObserver(this, "http-on-examine-merged-response");
  2197.     },
  2198.     
  2199.     // event related
  2200.     onModifyRequest: function(HttpChannel)
  2201.     {
  2202.         // force caching
  2203.         this.HttpFox.forceCaching(HttpChannel);
  2204.         
  2205.         var eventSourceData = new Object();
  2206.  
  2207.         // hook up more listeners
  2208.         HttpChannel.QueryInterface(Components.interfaces.nsIRequest);
  2209.         if (HttpChannel.loadGroup && HttpChannel.loadGroup.groupObserver) {
  2210.             // even more listeners
  2211.             var go = HttpChannel.loadGroup.groupObserver;
  2212.             go.QueryInterface(Components.interfaces.nsIWebProgress);
  2213.             try {
  2214.                 go.addProgressListener(this, 0xFE); // 0x2 or 0xff
  2215.             }
  2216.             catch(ex) {
  2217.                 // guess this means the request is aborted and/or cached.
  2218.             }
  2219.         }
  2220.         
  2221.         try {
  2222.             // assume it is always a new request
  2223.             var event = new HttpFoxRequestEvent(
  2224.                 this.HttpFox, 
  2225.                 HttpChannel, 
  2226.                 this.HttpFox.HttpFoxEventSourceType.ON_MODIFY_REQUEST, 
  2227.                 eventSourceData, 
  2228.                 utils.getContextFromRequest(HttpChannel));
  2229.             
  2230.             event.HttpFoxRequestEventSink = new HttpFoxRequestEventSink(this.HttpFox, HttpChannel);
  2231.                 
  2232.             this.HttpFox.handleRequestEvent(event);
  2233.             }
  2234.               
  2235.         catch(e) 
  2236.         {
  2237.             dump("\n* Observer EXC: " + e + "\n");
  2238.         }
  2239.     },
  2240.     
  2241.     onExamineResponse: function(HttpChannel) 
  2242.     {
  2243.         var eventSourceData = new Object();
  2244.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, HttpChannel, this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_RESPONSE, eventSourceData, utils.getContextFromRequest(HttpChannel)));
  2245.     },
  2246.     
  2247.     onExamineMergedResponse: function(HttpChannel) 
  2248.     {
  2249.         var eventSourceData = new Object();
  2250.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, HttpChannel, this.HttpFox.HttpFoxEventSourceType.ON_EXAMINE_MERGED_RESPONSE, eventSourceData, utils.getContextFromRequest(HttpChannel)));
  2251.     },
  2252.     
  2253.     // INTERFACE IMPLEMENTATIONS
  2254.     /**
  2255.     /* nsIWebProgressListener
  2256.     /**/
  2257.     onStateChange: function(progress, request, flags, status)
  2258.     {
  2259.         var eventSourceData = new Object();
  2260.         eventSourceData["flags"] = flags;
  2261.         eventSourceData["status"] = status;
  2262.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, request, this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_STATE_CHANGED, eventSourceData, utils.getContextFromRequest(request)));
  2263.     },
  2264.     
  2265.     onProgressChange: function(progress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) 
  2266.     {
  2267.         var eventSourceData = new Object();
  2268.         eventSourceData["curSelfProgress"] = curSelfProgress;
  2269.         eventSourceData["maxSelfProgress"] = maxSelfProgress;
  2270.         eventSourceData["curTotalProgress"] = curTotalProgress;
  2271.         eventSourceData["maxTotalProgress"] = maxTotalProgress;
  2272.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, request, this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_PROGRESS_CHANGED, eventSourceData, utils.getContextFromRequest(request)));
  2273.     },
  2274.     
  2275.     onLocationChange: function(progress, request, uri) 
  2276.     {
  2277.         var eventSourceData = new Object();
  2278.         eventSourceData["uri"] = uri;
  2279.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, request, this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_LOCATION_CHANGED, eventSourceData, utils.getContextFromRequest(request)));
  2280.     },
  2281.     
  2282.     onStatusChange: function(progress, request, status, message) 
  2283.     {
  2284.         var eventSourceData = new Object();
  2285.         eventSourceData["status"] = status;
  2286.         eventSourceData["message"] = message;
  2287.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, request, this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_STATUS_CHANGED, eventSourceData, utils.getContextFromRequest(request)));
  2288.     },
  2289.     
  2290.     onSecurityChange: function(progress, request, state) 
  2291.     {
  2292.         var eventSourceData = new Object();
  2293.         eventSourceData["state"] = state;
  2294.         this.HttpFox.handleRequestEvent(new HttpFoxRequestEvent(this.HttpFox, request, this.HttpFox.HttpFoxEventSourceType.WEBPROGRESS_ON_SECURITY_CHANGED, eventSourceData, utils.getContextFromRequest(request)));
  2295.     },
  2296.     /********************************************/
  2297.     
  2298.     /**
  2299.     * nsIObserver
  2300.     */
  2301.     observe: function(subject, topic, data) 
  2302.     {
  2303.         if (topic == 'http-on-modify-request') 
  2304.         {
  2305.             subject.QueryInterface(Components.interfaces.nsIHttpChannel);
  2306.             this.onModifyRequest(subject);
  2307.         } 
  2308.         else if (topic == 'http-on-examine-response') 
  2309.         {
  2310.             subject.QueryInterface(Components.interfaces.nsIHttpChannel);
  2311.             this.onExamineResponse(subject);
  2312.         } 
  2313.         else if (topic == 'http-on-examine-merged-response') 
  2314.         {
  2315.             subject.QueryInterface(Components.interfaces.nsIHttpChannel);
  2316.             this.onExamineMergedResponse(subject);
  2317.         }
  2318.     },
  2319.     /*********************************************/
  2320.         
  2321.     /**
  2322.     * nsISupportsString
  2323.     */
  2324.     data: "HttpFoxObserver",
  2325.     
  2326.     
  2327.     toString: function()
  2328.     {
  2329.         return "HttpFoxObserver";
  2330.     },
  2331.     /*********************************************/
  2332.     
  2333.     /**
  2334.     * nsISupports
  2335.     */
  2336.     QueryInterface: function(iid) 
  2337.     {
  2338.         if (!iid.equals(Components.interfaces.nsISupports) &&
  2339.             !iid.equals(Components.interfaces.nsISupportsWeakReference) &&
  2340.             !iid.equals(Components.interfaces.nsIObserver) &&
  2341.             !iid.equals(Components.interfaces.nsIWebProgressListener) &&
  2342.             !iid.equals(Components.interfaces.nsIURIContentListener) &&
  2343.             !iid.equals(Components.interfaces.nsIStreamListener) &&
  2344.             !iid.equals(Components.interfaces.nsIRequestObserver) &&
  2345.             !iid.equals(Components.interfaces.nsISupportsString))
  2346.         {
  2347.             throw Components.results.NS_ERROR_NO_INTERFACE;
  2348.         }
  2349.         
  2350.         return this;
  2351.     }
  2352.     /********************************************/
  2353. }
  2354. // ************************************************************************************************
  2355.  
  2356. function HttpFoxContext(win, browser, chrome, persistedState)
  2357. {
  2358.     this.windows = [];    
  2359.     this.panelMap = {};
  2360.     this.sidePanelNames = {};
  2361.     this.sourceCache = new HttpFoxSourceCache(win);
  2362. }
  2363. // ************************************************************************************************
  2364.  
  2365. // HttpFoxSourceCache
  2366. function HttpFoxSourceCache(win)
  2367. {
  2368.     this.charset = null;
  2369.     if (win != null) {
  2370.            this.charset = win.document.characterSet;
  2371.     }
  2372.     this.cache = {};
  2373. }
  2374.  
  2375. HttpFoxSourceCache.prototype =
  2376. {
  2377.     loadText: function(url)
  2378.     {
  2379.         var lines = this.load(url);
  2380.         return lines ? lines.join("\n") : null;
  2381.     },
  2382.     
  2383.     loadData: function(url, myPostData, ckey, request)
  2384.     {
  2385.         var data = this.load(url, myPostData, ckey, request);
  2386.         return data;
  2387.     },
  2388.         
  2389.     load: function(url, myPostData, ckey, request)
  2390.     {
  2391.         var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  2392.  
  2393.         var channel;
  2394.         try
  2395.         {
  2396.             channel = ioService.newChannel(url, null, null);
  2397.             channel.loadFlags |= utils.LOAD_FROM_CACHE | utils.LOAD_TARGETED | utils.VALIDATE_NEVER;
  2398.             channel.owner = new HttpFoxResponseLoaderFlagger();
  2399.         }
  2400.         catch(ex)
  2401.         {
  2402.             return;
  2403.         }
  2404.  
  2405.         if (channel instanceof Components.interfaces.nsIUploadChannel)
  2406.         {
  2407.             if (myPostData) 
  2408.             {
  2409.                 var inputStream = Components.classes["@mozilla.org/io/string-input-stream;1"].createInstance(Components.interfaces.nsIStringInputStream);
  2410.                 inputStream.setData(myPostData, myPostData.length);
  2411.  
  2412.                 var postStream = inputStream.QueryInterface(Components.interfaces.nsISeekableStream);
  2413.                 postStream.seek(0, 0);
  2414.                 
  2415.                 var uploadChannel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);
  2416.                 uploadChannel.setUploadStream(postStream, "application/x-www-form-urlencoded", -1);
  2417.                    
  2418.                 var cachingChannel = channel.QueryInterface(Components.interfaces.nsIHttpChannel);
  2419.                 var httpChannel = channel.QueryInterface(Components.interfaces.nsIHttpChannel);
  2420.                 httpChannel.requestMethod = "POST";
  2421.             }
  2422.         }
  2423.         
  2424.         if (channel instanceof Components.interfaces.nsICachingChannel)
  2425.         {
  2426.             var cacheChannel = channel.QueryInterface(Components.interfaces.nsICachingChannel);
  2427.             cacheChannel.loadFlags |= utils.LOAD_ONLY_FROM_CACHE | utils.VALIDATE_NEVER;
  2428.             cacheChannel.cacheKey = ckey;
  2429.         }
  2430.         
  2431.         var stream;
  2432.         try
  2433.         {
  2434.             var listener = new HttpFoxSourceCacheStreamListener(url, this, request, this.charset);
  2435.             channel.asyncOpen(listener, null);
  2436.         }
  2437.         catch(ex)
  2438.         {
  2439.             return;
  2440.         }
  2441.         
  2442.     },
  2443.     
  2444.     loadAsync: function(url, cb)
  2445.     {
  2446.         if (url in this.cache)
  2447.         {
  2448.             cb(this.cache[url], url);
  2449.             return;
  2450.         }
  2451.  
  2452.         var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  2453.  
  2454.         var channel = ioService.newChannel(url, null, null);
  2455.         channel.loadFlags |= utils.LOAD_FROM_CACHE | utils.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
  2456.  
  2457.         var listener = new HttpFoxSourceCacheStreamListener(url, this, cb);
  2458.         channel.asyncOpen(listener, null);            
  2459.     } 
  2460. }
  2461. // ************************************************************************************************
  2462.  
  2463. // HttpFoxSourceCacheStreamListener
  2464. function HttpFoxSourceCacheStreamListener(url, cache, request, charset)
  2465. {
  2466.     this.request = request;
  2467.     this.charset = charset;
  2468.     this.url = url;
  2469.     this.cache = cache;
  2470.     this.data = "";
  2471. }
  2472.  
  2473. HttpFoxSourceCacheStreamListener.prototype =
  2474. {
  2475.     onStartRequest: function(request, context)
  2476.     {},
  2477.  
  2478.     onStopRequest: function(request, context, status)
  2479.     {
  2480.         this.done = true;
  2481.         
  2482.         if (status != utils.NS_BINDING_ABORTED)
  2483.         {
  2484.             context = this.data;
  2485.             this.request.endGetRawContent(utils.convertToUnicode(this.data, this.charset), status);
  2486.         }
  2487.     },
  2488.  
  2489.     onDataAvailable: function(request, context, inStr, sourceOffset, count)
  2490.     {
  2491.         this.data += utils.readFromStream_Binary(inStr, this.charset);
  2492.     }
  2493. };
  2494. // ************************************************************************************************
  2495.  
  2496. // HttpFoxResponseLoaderFlagger
  2497. function HttpFoxResponseLoaderFlagger() 
  2498. {}
  2499. HttpFoxResponseLoaderFlagger.prototype =
  2500. {
  2501.     data: "HttpFoxResponseLoaderFlagger",
  2502.     
  2503.     toString: function()
  2504.     {
  2505.         return "HttpFoxResponseLoaderFlagger";
  2506.     },
  2507.     
  2508.     QueryInterface: function(iid)
  2509.     {
  2510.         if (iid.equals(Components.interfaces.nsISupportsString) ||
  2511.             iid.equals(Components.interfaces.nsISupports))
  2512.             return this;
  2513.         throw Components.results.NS_NOINTERFACE;
  2514.     }
  2515. }
  2516. // ************************************************************************************************
  2517.  
  2518.  
  2519.  
  2520. // HttpFoxHeaderInfo
  2521. function HttpFoxHeaderInfo()
  2522. {
  2523.     this.init();
  2524. }
  2525. HttpFoxHeaderInfo.prototype = 
  2526. {
  2527.     Headers: null,
  2528.     
  2529.     init: function()
  2530.     {
  2531.         this.Headers = new Array();
  2532.     },
  2533.     
  2534.     visitHeader: function(name, value)
  2535.     {
  2536.         this.Headers[name] = value;
  2537.     }
  2538. }
  2539. // ************************************************************************************************
  2540.  
  2541.  
  2542. // HttpFoxPostDataHandler
  2543. // Contains code from LiveHeaders and TamperData
  2544. function HttpFoxPostDataHandler(hfRequest) 
  2545. {
  2546.     this.request = hfRequest;
  2547.     this.request.IsPostDataMIME = false;
  2548.     this.seekablestream = this.request.HttpChannel.uploadStream.QueryInterface(Components.interfaces.nsISeekableStream);
  2549.     this.stream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
  2550.     this.stream.init(this.seekablestream);
  2551.  
  2552.     // Check if the stream has headers
  2553.     this.hasheaders = false;
  2554.     this.body = 0;
  2555.     this.isBinary = true;
  2556.     if (this.seekablestream instanceof Components.interfaces.nsIMIMEInputStream) 
  2557.     {
  2558.         this.seekablestream.QueryInterface(Components.interfaces.nsIMIMEInputStream);
  2559.         this.hasheaders = true;
  2560.         this.body = -1; // Must read header to find body
  2561.         this.isBinary = false;
  2562.     } 
  2563.     else if (this.seekablestream instanceof Components.interfaces.nsIStringInputStream) 
  2564.     {
  2565.         this.seekablestream.QueryInterface(Components.interfaces.nsIStringInputStream);
  2566.         this.hasheaders = true;
  2567.         this.body = -1; // Must read header to find body
  2568.     }
  2569. }
  2570.  
  2571. HttpFoxPostDataHandler.prototype = 
  2572. {
  2573.     rewind: function() 
  2574.     {
  2575.         this.seekablestream.seek(0, 0);
  2576.     },
  2577.  
  2578.     tell: function() 
  2579.     {
  2580.         return this.seekablestream.tell();
  2581.     },
  2582.  
  2583.     readLine: function() 
  2584.     {
  2585.         var line = "";
  2586.         var size = this.stream.available();
  2587.         for (var i = 0; i < size; i++) 
  2588.         {
  2589.             var c = this.stream.read(1);
  2590.             if (c == '\r') 
  2591.             {} 
  2592.             else if (c == '\n') 
  2593.             {
  2594.                 break;
  2595.             } 
  2596.             else
  2597.             {
  2598.                 line += c;
  2599.             }
  2600.         }
  2601.         return line;
  2602.     },
  2603.  
  2604.     getPostHeaders: function() 
  2605.     {
  2606.         if (this.hasheaders) 
  2607.         {
  2608.             this.rewind();
  2609.             var line = this.readLine();
  2610.             while(line) 
  2611.             {
  2612.                 if (this.request) 
  2613.                 {
  2614.                     var tmp = line.split(/:\s?/);
  2615.                     this.addPostHeader(tmp[0], tmp[1]);
  2616.                     // check if MIME postdata
  2617.                     if (tmp[0].toLowerCase() == "content-type" && tmp[1].indexOf("multipart") != "-1") 
  2618.                     {
  2619.                         this.isBinary = true;
  2620.                         this.request.IsPostDataMIME = true;
  2621.                         this.request.PostDataMIMEBoundary = "--" + tmp[1].split("boundary=")[1];
  2622.                         if (this.request.PostDataMIMEBoundary.indexOf("\"") == 0)
  2623.                         {
  2624.                             this.request.PostDataMIMEBoundary = this.request.PostDataMIMEBoundary.substr(1, this.request.PostDataMIMEBoundary.length - 2);
  2625.                         }
  2626.                     }
  2627.                 }
  2628.                 line = this.readLine();
  2629.             }
  2630.             this.body = this.tell();
  2631.         }
  2632.     },
  2633.     
  2634.     addPostHeader: function(name, value)
  2635.     {
  2636.         if (!this.request.PostDataHeaders) 
  2637.         {
  2638.             this.request.PostDataHeaders = new Array;
  2639.         }
  2640.         this.request.PostDataHeaders[name] = value;
  2641.     },
  2642.  
  2643.     clearPostHeaders : function() 
  2644.     {
  2645.         if (this.request.PostDataHeaders) 
  2646.         {
  2647.             delete this.request.PostDataHeaders;
  2648.         }
  2649.     },
  2650.     
  2651.     getPostData: function() 
  2652.     {
  2653.         // Position the stream to the start of the body
  2654.         if (this.body < 0 || this.seekablestream.tell() != this.body) 
  2655.         {
  2656.             this.getPostHeaders();
  2657.         }
  2658.     
  2659.         var size = this.stream.available();
  2660.         if (size == 0 && this.body != 0) 
  2661.         {
  2662.             // whoops, there weren't really headers..
  2663.             this.rewind();
  2664.             this.clearPostHeaders();
  2665.             size = this.stream.available();
  2666.         }
  2667.         
  2668.         // read post body (only if non-binary/too big)
  2669.         var postString = "";
  2670.         
  2671.         try 
  2672.         {
  2673.             if (size < 500000)
  2674.             {
  2675.                 // This is to avoid 'NS_BASE_STREAM_CLOSED' exception that may occurs
  2676.                 // See bug #188328.
  2677.                 for (var i = 0; i < size; i++) 
  2678.                 {
  2679.                     var c = this.stream.read(1);
  2680.                     c ? postString += c : postString += '\0';
  2681.                 }    
  2682.             }
  2683.             else 
  2684.             {
  2685.                 this.request.IsPostDataTooBig = true;
  2686.             }
  2687.         } 
  2688.         catch(e)
  2689.         {
  2690.             dump("\nExc: " + e)
  2691.             return "" + ex;
  2692.         } 
  2693.         finally 
  2694.         {
  2695.             this.rewind();
  2696.         }
  2697.         
  2698.         // if mime than try to split in parts
  2699.         if (this.request.IsPostDataMIME) 
  2700.         {
  2701.             this.request.PostData = postString;
  2702.             this.request.PostDataMIMEParts = new Array();
  2703.             
  2704.             if (!this.request.IsPostDataTooBig)
  2705.             {
  2706.                 var rawMimeParts = new Array();
  2707.                 rawMimeParts = postString.split(this.request.PostDataMIMEBoundary);
  2708.                 
  2709.                 var ws = "\n";
  2710.                 if (rawMimeParts[1].indexOf("\r\n") == 0)
  2711.                 {
  2712.                     ws = "\r\n";
  2713.                 }
  2714.                 else if (rawMimeParts[1].indexOf("\r") == 0)
  2715.                 {
  2716.                     ws = "\r";
  2717.                 }
  2718.                 
  2719.                 for (var i = 1; rawMimeParts[i]; i++)
  2720.                 {
  2721.                     try 
  2722.                     {
  2723.                             
  2724.                         var mimePartData = new Object();
  2725.                         var rawMimePartParts = new Array();
  2726.                         rawMimePartParts = rawMimeParts[i].split(ws + ws);    
  2727.                         
  2728.                         var varname = null;
  2729.                         RegExp.lastIndex = 0;
  2730.                         if (rawMimePartParts[0].match(/\bname="([^"]+)"/i)) 
  2731.                         {
  2732.                             varname = RegExp.$1;
  2733.                         }
  2734.                         if (!varname) 
  2735.                         {
  2736.                             RegExp.lastIndex = 0;
  2737.                             if(rawMimePartParts[0].match(/\bname=([^\s:;]+)/i)) 
  2738.                             {
  2739.                                 varname = RegExp.$1;
  2740.                             }
  2741.                         }
  2742.                         
  2743.                         if (varname != null)
  2744.                         {
  2745.                             var filename = null;
  2746.                             RegExp.lastIndex = 0;
  2747.                             if (rawMimePartParts[0].match(/\b(filename="[^"]*")/i)) 
  2748.                             {
  2749.                                 filename = RegExp.$1;
  2750.                             }
  2751.                             if (!filename) 
  2752.                             {
  2753.                                 RegExp.lastIndex = 0;
  2754.                                 if(rawMimePartParts[0].match(/\b(filename=[^\s:;]+)/i)) 
  2755.                                 {
  2756.                                     filename = RegExp.$1;
  2757.                                 }
  2758.                             }
  2759.             
  2760.                             var ctype = null;
  2761.                             RegExp.lastIndex = 0;
  2762.                             if (rawMimePartParts[0].match(/\b(Content-type:\s*"[^"]+)"/i)) 
  2763.                             {
  2764.                                 ctype = RegExp.$1;
  2765.                             }
  2766.                             if (!ctype) 
  2767.                             {
  2768.                                 RegExp.lastIndex = 0;
  2769.                                 if (rawMimePartParts[0].match(/\b(Content-Type:\s*[^\s:;]+)/i)) {
  2770.                                     ctype = RegExp.$1;
  2771.                                 }
  2772.                             }
  2773.                             
  2774.                             // value
  2775.                             var value = rawMimePartParts[1].trim();
  2776.                             
  2777.                             mimePartData["varname"] = varname;
  2778.                             mimePartData["filename"] = filename;
  2779.                             mimePartData["ctype"] = ctype;
  2780.                             mimePartData["value"] = value;
  2781.                             
  2782.                             this.request.PostDataMIMEParts.push(mimePartData);
  2783.                         }
  2784.                     }
  2785.                     catch(e)
  2786.                     {
  2787.                         dump("\n\nEXC: " + e);
  2788.                     }
  2789.                 }
  2790.                 
  2791.                 return null;
  2792.             }
  2793.         }
  2794.         
  2795.         // strip off trailing \r\n's
  2796.         while (postString.indexOf("\r\n") == (postString.length - 2))
  2797.         {
  2798.             postString = postString.substring(0, postString.length - 2);
  2799.         }
  2800.         this.request.PostData = postString;
  2801.         
  2802.         // check if url parameter style
  2803.         if (this.request.PostData.match(/^&?([^=&<>]+=[^=&]*&?)+/i)) 
  2804.         {
  2805.             // split parameters (only non-mime bodies)
  2806.             this.request.PostDataParameters = new Array();
  2807.             var postDataParts = this.request.PostData.split("&");
  2808.             for (var i in postDataParts)
  2809.             {
  2810.                 var nameValuePair = postDataParts[i].split("=");
  2811.                 this.request.PostDataParameters.push([nameValuePair[0], nameValuePair[1]]);
  2812.             }
  2813.             return null;        
  2814.         }
  2815.         
  2816.         // no parseable content. display raw.
  2817.         this.request.PostDataParameters = null;
  2818.         return null;
  2819.     }
  2820. }
  2821. // ************************************************************************************************
  2822.  
  2823. // HttpFoxRequestLogData
  2824. function HttpFoxRequestLogData(request)
  2825. {
  2826.     this.init(request);
  2827. }
  2828. HttpFoxRequestLogData.prototype = 
  2829. {
  2830.     EventSource: null,
  2831.     EventSourceData: null,
  2832.     Timestamp: null,
  2833.     StateFlags: null,
  2834.     IsFromCache: null,
  2835.     Url: null,
  2836.     IsPending: null,
  2837.     BytesLoaded: null,
  2838.     BytesLoadedTotal: null,
  2839.     ResponseStatus: null,
  2840.     ResponseStatusText: null,
  2841.     Status: null,
  2842.     ContentType: null,
  2843.     ContentCharset: null,
  2844.     ContentLength: null,
  2845.     RequestSucceeded: null,
  2846.     IsNoStoreResponse: null,
  2847.     IsNoCacheResponse: null,
  2848.     EntityId: null,
  2849.     Priority: null,
  2850.     HasCacheInfo: null,
  2851.     
  2852.     init: function(request)
  2853.     {
  2854.         this.EventSource = request.EventSource;
  2855.         this.EventSourceData = new Object();
  2856.         for (i in request.EventSourceData)
  2857.         {
  2858.             this.EventSourceData[i] = request.EventSourceData[i];
  2859.         }
  2860.         this.Timestamp = request.Timestamp;
  2861.         this.StateFlags = request.StateFlags;
  2862.         this.IsFromCache = request.IsFromCache;
  2863.         this.Url = request.Url;
  2864.         this.IsPending = request.IsPending;
  2865.         this.BytesLoaded = request.BytesLoaded;
  2866.         this.BytesLoadedTotal = request.BytesLoadedTotal;
  2867.         this.ResponseStatus = request.ResponseStatus;
  2868.         this.ResponseStatusText = request.ResponseStatusText;
  2869.         this.Status = request.Status;
  2870.         this.ContentType = request.ContentType;
  2871.         this.ContentCharset = request.ContentCharset;
  2872.         this.ContentLength = request.ContentLength;
  2873.         this.RequestSucceeded = request.RequestSucceeded;
  2874.         this.IsNoStoreResponse = request.IsNoStoreResponse;
  2875.         this.IsNoCacheResponse = request.IsNoCacheResponse;
  2876.         this.EntityId = request.EntityId;
  2877.         this.Priority = request.Priority;
  2878.         this.HasCacheInfo = request.HasCacheInfo;
  2879.     }
  2880. }
  2881. // ************************************************************************************************
  2882.  
  2883. // UTIL FUNCTIONS
  2884.  
  2885. // ************************************************************************************************
  2886.  
  2887. String.prototype.trim = function(x) 
  2888. {
  2889.     if (x=='left')
  2890.         return this.replace(/^\s*/,'');
  2891.     if (x=='right')
  2892.         return this.replace(/\s*$/,'');
  2893.     if (x=='normalize')
  2894.         return this.replace(/\s{2,}/g,' ').trim();
  2895.         
  2896.     return this.trim('left').trim('right');
  2897. }
  2898. // ************************************************************************************************
  2899.  
  2900. var utils = {
  2901.     LOAD_FROM_CACHE: Components.interfaces.nsIRequest.LOAD_FROM_CACHE,
  2902.     VALIDATE_NEVER: Components.interfaces.nsIRequest.VALIDATE_NEVER,
  2903.     LOAD_TARGETED: Components.interfaces.nsIChannel.LOAD_TARGETED,
  2904.     LOAD_BYPASS_LOCAL_CACHE_IF_BUSY: Components.interfaces.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY,
  2905.     LOAD_ONLY_FROM_CACHE: Components.interfaces.nsICachingChannel.LOAD_ONLY_FROM_CACHE,
  2906.     NS_BINDING_ABORTED: 0x804b0002,
  2907.  
  2908.     // Utility function, dump an object by reflexion up to niv level
  2909.     dumpall: function(name, obj, niv) 
  2910.     {
  2911.         if (!niv) {
  2912.             niv=1;
  2913.         }
  2914.         var dumpdict = new Object();
  2915.     
  2916.         dump ("\n\n-------------------------------------------------------\n");
  2917.         dump ("Dump of the object: " + name + " (" + niv + " levels)\n");
  2918.         dump ("Address: " + obj + "\n");
  2919.         dump ("Interfaces: ");
  2920.         
  2921.         for (var i in Components.interfaces) 
  2922.         {
  2923.             try 
  2924.             {
  2925.                 obj.QueryInterface(Components.interfaces[i]);
  2926.                 dump("" + Components.interfaces[i] + ", ");
  2927.             } 
  2928.             catch(ex) 
  2929.             {}
  2930.         }
  2931.         dump("\n");
  2932.         this._dumpall(dumpdict,obj,niv,"","");
  2933.         dump ("\n\n-------------------------------------------------------\n\n");
  2934.     
  2935.         for (i in dumpdict) 
  2936.         {
  2937.             delete dumpdict[i];
  2938.         }
  2939.     },
  2940.     
  2941.     _dumpall: function(dumpdict, obj, niv, tab, path) 
  2942.     {
  2943.         if (obj in dumpdict) 
  2944.         {
  2945.             dump(" (Already dumped)");
  2946.         } 
  2947.         else 
  2948.         {
  2949.             dumpdict[obj]=1;
  2950.             
  2951.             var i, r, str, typ;
  2952.             for (i in obj) 
  2953.             {
  2954.                 try 
  2955.                 {
  2956.                     str = String(obj[i]).replace(/\n/g, "\n" + tab);
  2957.                 } 
  2958.                 catch(ex) 
  2959.                 {
  2960.                     str = String(ex);
  2961.                 }
  2962.                 try 
  2963.                 {
  2964.                     typ = "" + typeof(obj[i]);
  2965.                 } 
  2966.                 catch(ex) 
  2967.                 {
  2968.                     typ = "unknown";
  2969.                 }
  2970.                 dump ("\n" + tab + i + " (" + typ + (path ? ", " + path : "") + "): " + str);
  2971.                 if ((niv > 1) && (typ == "object")) 
  2972.                 {
  2973.                     this._dumpall(dumpdict, obj[i], niv-1, tab + "\t", (path ? path + "->" + i : i));
  2974.                 }
  2975.             }
  2976.         }
  2977.     },
  2978.     // ************************************************************************************************
  2979.     
  2980.     readFromStream_Binary: function(stream, charset)
  2981.     {
  2982.         var bstream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
  2983.         bstream.setInputStream(stream);
  2984.     
  2985.         var bytes = bstream.readBytes(bstream.available());
  2986.         return bytes;
  2987.     },
  2988.     //************************************************************************************************
  2989.     
  2990.     // context helper functions
  2991.     getContextFromWindow: function(win)
  2992.     {
  2993.         if (win == null) 
  2994.         {
  2995.             return new HttpFoxContext(null, null, null, false);
  2996.         }
  2997.         else 
  2998.         {
  2999.             var browser = this.getBrowserByWindow(win);
  3000.             var chrome = browser ? browser.chrome : null;
  3001.             return new HttpFoxContext(win, browser, chrome, false);    
  3002.         }
  3003.     },
  3004.     
  3005.     getContextFromRequest: function(request)
  3006.     {
  3007.         var win = null;
  3008.         var browser = null;
  3009.         
  3010.         try 
  3011.         {
  3012.             request.QueryInterface(Components.interfaces.nsIChannel);
  3013.         }
  3014.         catch(ex)
  3015.         {
  3016.             return new HttpFoxContext(null, null, null, false);
  3017.         }
  3018.         
  3019.         if (request.loadGroup == null || request.loadGroup.groupObserver == null) 
  3020.         {
  3021.             win = null;
  3022.             return new HttpFoxContext(null, null, null, false);
  3023.         }
  3024.         
  3025.         var go = request.loadGroup.groupObserver;
  3026.         go.QueryInterface(Components.interfaces.nsIWebProgress);
  3027.         win = go.DOMWindow;
  3028.         browser = this.getBrowserByWindow(win);
  3029.         var chrome = browser ? browser.chrome : null;
  3030.     
  3031.         return new HttpFoxContext(win, browser, chrome, false);
  3032.     },
  3033.     
  3034.     getBrowserByWindow: function(win)
  3035.     {
  3036.         return null;
  3037.     },
  3038.     // ************************************************************************************************
  3039.     
  3040.     convertToUnicode: function(text, charset)
  3041.     {
  3042.         try
  3043.         {
  3044.             var conv = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].getService(Components.interfaces.nsIScriptableUnicodeConverter);
  3045.             conv.charset = charset ? charset : "UTF-8";
  3046.             return conv.ConvertToUnicode(text);
  3047.         }
  3048.         catch (exc)
  3049.         {
  3050.             return text;
  3051.         }
  3052.     },
  3053.     // ************************************************************************************************
  3054.     
  3055.     // Get the cookies
  3056.     getStoredCookies: function(host, path)
  3057.     {
  3058.         var cookies = new Array();
  3059.         
  3060.         // If the host is set
  3061.         if(host)
  3062.         {
  3063.             var cookie            = null;
  3064.             var cookieEnumeration = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager).enumerator;
  3065.             var cookieHost        = null;
  3066.             var cookiePath        = null;
  3067.     
  3068.             // Loop through the cookies
  3069.             while(cookieEnumeration.hasMoreElements())
  3070.             {
  3071.                 cookie = cookieEnumeration.getNext().QueryInterface(Components.interfaces.nsICookie);
  3072.     
  3073.                 cookieHost = cookie.host;
  3074.                 cookiePath = cookie.path;
  3075.     
  3076.                 // If there is a host and path for this cookie
  3077.                 if(cookieHost && cookiePath)
  3078.                 {
  3079.                     // If the cookie host starts with '.'
  3080.                     if(cookieHost.charAt(0) == ".")
  3081.                     {
  3082.                         cookieHost = cookieHost.substring(1);
  3083.                     }
  3084.     
  3085.                     // If the host and cookie host and path and cookie path match
  3086.                     //if((host == cookieHost || host.indexOf("." + cookieHost) != -1) && (path == cookiePath || path.indexOf(cookiePath) == 0))
  3087.                     if((host == cookieHost || host.indexOf("." + cookieHost) != -1) && (path == cookiePath || path.indexOf(cookiePath) == 0)) 
  3088.                     {
  3089.                         cookies.push(cookie);
  3090.                     }
  3091.                 }
  3092.             }
  3093.         }
  3094.     
  3095.         return cookies;
  3096.     },
  3097.     
  3098.     HttpFoxNsResultErrors: 
  3099.     {
  3100.         NS_ERROR_BASE: 0xC1F30000,
  3101.         NS_ERROR_NOT_IMPLEMENTED: 0x80004001,
  3102.         NS_ERROR_INVALID_POINTER: 0x80004003,
  3103.         NS_ERROR_ABORT: 0x80004004,
  3104.         NS_ERROR_FAILURE: 0x80004005,
  3105.         NS_ERROR_UNEXPECTED: 0x8000FFFF,
  3106.         NS_ERROR_PROXY_INVALID_IN_PARAMETER: 0x80010010,
  3107.         NS_ERROR_PROXY_INVALID_OUT_PARAMETER: 0x80010011,
  3108.         NS_ERROR_NO_AGGREGATION: 0x80040110,
  3109.         NS_ERROR_NOT_AVAILABLE: 0x80040111,
  3110.         NS_ERROR_FACTORY_NOT_REGISTERED: 0x80040154,
  3111.         NS_ERROR_FACTORY_REGISTER_AGAIN: 0x80040155,
  3112.         NS_ERROR_FACTORY_NOT_LOADED: 0x800401F8,
  3113.         NS_ERROR_OUT_OF_MEMORY: 0x8007000E,
  3114.         NS_ERROR_ILLEGAL_VALUE: 0x80070057,
  3115.         NS_ERROR_CANNOT_CONVERT_DATA: 0x80460001,
  3116.         NS_ERROR_OBJECT_IS_IMMUTABLE: 0x80460002,
  3117.         NS_ERROR_LOSS_OF_SIGNIFICANT_DATA: 0x80460003,
  3118.         NS_ERROR_SERVICE_NOT_AVAILABLE: 0x80460016,
  3119.         NS_ERROR_IS_DIR: 0x80460018,
  3120.         NS_ERROR_ILLEGAL_DURING_SHUTDOWN: 0x8046001E,
  3121.         NS_BASE_STREAM_CLOSED: 0x80470002,
  3122.         NS_BASE_STREAM_OSERROR: 0x80470003,
  3123.         NS_BASE_STREAM_ILLEGAL_ARGS: 0x80470004,
  3124.         NS_BASE_STREAM_NO_CONVERTER: 0x80470005,
  3125.         NS_BASE_STREAM_BAD_CONVERSION: 0x80470006,
  3126.         NS_BASE_STREAM_WOULD_BLOCK: 0x80470007,
  3127.         NS_ERROR_GFX_PRINTER_CMD_NOT_FOUND: 0x80480002,
  3128.         NS_ERROR_GFX_PRINTER_CMD_FAILURE: 0x80480003,
  3129.         NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE: 0x80480004,
  3130.         NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND: 0x80480005,
  3131.         NS_ERROR_GFX_PRINTER_ACCESS_DENIED: 0x80480006,
  3132.         NS_ERROR_GFX_PRINTER_INVALID_ATTRIBUTE: 0x80480007,
  3133.         NS_ERROR_GFX_PRINTER_PRINTER_NOT_READY: 0x80480009,
  3134.         NS_ERROR_GFX_PRINTER_OUT_OF_PAPER: 0x8048000A,
  3135.         NS_ERROR_GFX_PRINTER_PRINTER_IO_ERROR: 0x8048000B,
  3136.         NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE: 0x8048000C,
  3137.         NS_ERROR_GFX_PRINTER_FILE_IO_ERROR: 0x8048000D,
  3138.         NS_ERROR_GFX_PRINTER_PRINTPREVIEW: 0x8048000E,
  3139.         NS_ERROR_GFX_PRINTER_STARTDOC: 0x8048000F,
  3140.         NS_ERROR_GFX_PRINTER_ENDDOC: 0x80480010,
  3141.         NS_ERROR_GFX_PRINTER_STARTPAGE: 0x80480011,
  3142.         NS_ERROR_GFX_PRINTER_ENDPAGE: 0x80480012,
  3143.         NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW: 0x80480013,
  3144.         NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED: 0x80480014,
  3145.         NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED: 0x80480015,
  3146.         NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED: 0x80480016,
  3147.         NS_ERROR_GFX_PRINTER_TOO_MANY_COPIES: 0x80480017,
  3148.         NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR: 0x80480018,
  3149.         NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP: 0x80480019,
  3150.         NS_ERROR_GFX_PRINTER_DOC_WAS_DESTORYED: 0x8048001A,
  3151.         NS_ERROR_GFX_PRINTER_NO_XUL: 0x8048001B,
  3152.         NS_ERROR_GFX_NO_PRINTDIALOG_IN_TOOLKIT: 0x8048001C,
  3153.         NS_ERROR_GFX_NO_PRINTROMPTSERVICE: 0x8048001D,
  3154.         NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED: 0x8048001E,
  3155.         NS_ERROR_GFX_PRINTER_DOC_IS_BUSY: 0x8048001F,
  3156.         NS_ERROR_GFX_PRINTING_NOT_IMPLEMENTED: 0x80480020,
  3157.         NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE: 0x80480021,
  3158.         NS_ERROR_GFX_PRINTER_RESOLUTION_NOT_SUPPORTED: 0x80480022,
  3159.         NS_BINDING_FAILED: 0x804B0001,
  3160.         NS_BINDING_ABORTED: 0x804B0002,
  3161.         NS_BINDING_REDIRECTED: 0x804B0003,
  3162.         NS_BINDING_RETARGETED: 0x804B0004,
  3163.         NS_ERROR_MALFORMED_URI: 0x804B000A,
  3164.         NS_ERROR_ALREADY_CONNECTED: 0x804B000B,
  3165.         NS_ERROR_NOT_CONNECTED: 0x804B000C,
  3166.         NS_ERROR_CONNECTION_REFUSED: 0x804B000D,
  3167.         NS_ERROR_NET_TIMEOUT: 0x804B000E,
  3168.         NS_ERROR_IN_PROGRESS: 0x804B000F,
  3169.         NS_ERROR_OFFLINE: 0x804B0010,
  3170.         NS_ERROR_NO_CONTENT: 0x804B0011,
  3171.         NS_ERROR_UNKNOWN_PROTOCOL: 0x804B0012,
  3172.         NS_ERROR_PORT_ACCESS_NOT_ALLOWED: 0x804B0013,
  3173.         NS_ERROR_NET_RESET: 0x804B0014,
  3174.         NS_ERROR_FTP_LOGIN: 0x804B0015,
  3175.         NS_ERROR_FTP_CWD: 0x804B0016,
  3176.         NS_ERROR_FTP_PASV: 0x804B0017,
  3177.         NS_ERROR_FTP_PWD: 0x804B0018,
  3178.         NS_ERROR_NOT_RESUMABLE: 0x804B0019,
  3179.         NS_ERROR_INVALID_CONTENT_ENCODING: 0x804B001B,
  3180.         NS_ERROR_FTP_LIST: 0x804B001C,
  3181.         NS_ERROR_UNKNOWN_HOST: 0x804B001E,
  3182.         NS_ERROR_REDIRECT_LOOP: 0x804B001F,
  3183.         NS_ERROR_ENTITY_CHANGED: 0x804B0020,
  3184.         NS_ERROR_UNKNOWN_PROXY_HOST: 0x804B002A,
  3185.         NS_ERROR_UNKNOWN_SOCKET_TYPE: 0x804B0033,
  3186.         NS_ERROR_SOCKET_CREATE_FAILED: 0x804B0034,
  3187.         NS_ERROR_CACHE_KEY_NOT_FOUND: 0x804B003D,
  3188.         NS_ERROR_CACHE_DATA_IS_STREAM: 0x804B003E,
  3189.         NS_ERROR_CACHE_DATA_IS_NOT_STREAM: 0x804B003F,
  3190.         NS_ERROR_CACHE_WAIT_FOR_VALIDATION: 0x804B0040,
  3191.         NS_ERROR_CACHE_ENTRY_DOOMED: 0x804B0041,
  3192.         NS_ERROR_CACHE_READ_ACCESS_DENIED: 0x804B0042,
  3193.         NS_ERROR_CACHE_WRITE_ACCESS_DENIED: 0x804B0043,
  3194.         NS_ERROR_CACHE_IN_USE: 0x804B0044,
  3195.         NS_ERROR_DOCUMENT_NOT_CACHED: 0x804B0046,
  3196.         NS_ERROR_NET_INTERRUPT: 0x804B0047,
  3197.         NS_ERROR_PROXY_CONNECTION_REFUSED: 0x804B0048,
  3198.         NS_ERROR_ALREADY_OPENED: 0x804B0049,
  3199.         NS_ERROR_UNSAFE_CONTENT_TYPE: 0x804B004A,
  3200.         NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS: 0x804B0050,
  3201.         NS_ERROR_HOST_IS_IP_ADDRESS: 0x804B0051,
  3202.         NS_ERROR_PLUGINS_PLUGINSNOTCHANGED: 0x804C03E8,
  3203.         NS_ERROR_PLUGIN_DISABLED: 0x804C03E9,
  3204.         NS_ERROR_PLUGIN_BLOCKLISTED: 0x804C03EA,
  3205.         NS_ERROR_HTMLPARSER_EOF: 0x804E03E8,
  3206.         NS_ERROR_HTMLPARSER_UNKNOWN: 0x804E03E9,
  3207.         NS_ERROR_HTMLPARSER_CANTPROPAGATE: 0x804E03EA,
  3208.         NS_ERROR_HTMLPARSER_CONTEXTMISMATCH: 0x804E03EB,
  3209.         NS_ERROR_HTMLPARSER_BADFILENAME: 0x804E03EC,
  3210.         NS_ERROR_HTMLPARSER_BADURL: 0x804E03ED,
  3211.         NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT: 0x804E03EE,
  3212.         NS_ERROR_HTMLPARSER_INTERRUPTED: 0x804E03EF,
  3213.         NS_ERROR_HTMLPARSER_BLOCK: 0x804E03F0,
  3214.         NS_ERROR_HTMLPARSER_BADTOKENIZER: 0x804E03F1,
  3215.         NS_ERROR_HTMLPARSER_BADATTRIBUTE: 0x804E03F2,
  3216.         NS_ERROR_HTMLPARSER_UNRESOLVEDDTD: 0x804E03F3,
  3217.         NS_ERROR_HTMLPARSER_MISPLACEDTABLECONTENT: 0x804E03F4,
  3218.         NS_ERROR_HTMLPARSER_BADDTD: 0x804E03F5,
  3219.         NS_ERROR_HTMLPARSER_BADCONTEXT: 0x804E03F6,
  3220.         NS_ERROR_HTMLPARSER_STOPPARSING: 0x804E03F7,
  3221.         NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL: 0x804E03F8,
  3222.         NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP: 0x804E03F9,
  3223.         NS_ERROR_HTMLPARSER_FAKE_ENDTAG: 0x804E03FA,
  3224.         NS_ERROR_HTMLPARSER_INVALID_COMMENT: 0x804E03FB,
  3225.         NS_ERROR_UCONV_NOCONV: 0x80500001,
  3226.         NS_ERROR_UDEC_ILLEGALINPUT: 0x8050000E,
  3227.         NS_ERROR_ILLEGAL_INPUT: 0x8050000E,
  3228.         NS_ERROR_REG_BADTYPE: 0x80510001,
  3229.         NS_ERROR_REG_BADTYPE: 0x80510001,
  3230.         NS_ERROR_REG_NOT_FOUND: 0x80510003,
  3231.         NS_ERROR_REG_NOT_FOUND: 0x80510003,
  3232.         NS_ERROR_REG_NOFILE: 0x80510004,
  3233.         NS_ERROR_REG_NOFILE: 0x80510004,
  3234.         NS_ERROR_REG_BUFFER_TOO_SMALL: 0x80510005,
  3235.         NS_ERROR_REG_BUFFER_TOO_SMALL: 0x80510005,
  3236.         NS_ERROR_REG_NAME_TOO_LONG: 0x80510006,
  3237.         NS_ERROR_REG_NAME_TOO_LONG: 0x80510006,
  3238.         NS_ERROR_REG_NO_PATH: 0x80510007,
  3239.         NS_ERROR_REG_NO_PATH: 0x80510007,
  3240.         NS_ERROR_REG_READ_ONLY: 0x80510008,
  3241.         NS_ERROR_REG_READ_ONLY: 0x80510008,
  3242.         NS_ERROR_REG_BAD_UTF8: 0x80510009,
  3243.         NS_ERROR_REG_BAD_UTF8: 0x80510009,
  3244.         NS_ERROR_FILE_UNRECOGNIZED_PATH: 0x80520001,
  3245.         NS_ERROR_FILE_UNRESOLVABLE_SYMLINK: 0x80520002,
  3246.         NS_ERROR_FILE_EXECUTION_FAILED: 0x80520003,
  3247.         NS_ERROR_FILE_UNKNOWN_TYPE: 0x80520004,
  3248.         NS_ERROR_FILE_DESTINATION_NOT_DIR: 0x80520005,
  3249.         NS_ERROR_FILE_TARGET_DOES_NOT_EXIST: 0x80520006,
  3250.         NS_ERROR_FILE_COPY_OR_MOVE_FAILED: 0x80520007,
  3251.         NS_ERROR_FILE_ALREADY_EXISTS: 0x80520008,
  3252.         NS_ERROR_FILE_INVALID_PATH: 0x80520009,
  3253.         NS_ERROR_FILE_DISK_FULL: 0x8052000A,
  3254.         NS_ERROR_FILE_CORRUPTED: 0x8052000B,
  3255.         NS_ERROR_FILE_NOT_DIRECTORY: 0x8052000C,
  3256.         NS_ERROR_FILE_IS_DIRECTORY: 0x8052000D,
  3257.         NS_ERROR_FILE_IS_LOCKED: 0x8052000E,
  3258.         NS_ERROR_FILE_TOO_BIG: 0x8052000F,
  3259.         NS_ERROR_FILE_NO_DEVICE_SPACE: 0x80520010,
  3260.         NS_ERROR_FILE_NAME_TOO_LONG: 0x80520011,
  3261.         NS_ERROR_FILE_NOT_FOUND: 0x80520012,
  3262.         NS_ERROR_FILE_READ_ONLY: 0x80520013,
  3263.         NS_ERROR_FILE_DIR_NOT_EMPTY: 0x80520014,
  3264.         NS_ERROR_FILE_ACCESS_DENIED: 0x80520015,
  3265.         NS_ERROR_DOM_INDEX_SIZE_ERR: 0x80530001,
  3266.         NS_ERROR_DOM_DOMSTRING_SIZE_ERR: 0x80530002,
  3267.         NS_ERROR_DOM_HIERARCHY_REQUEST_ERR: 0x80530003,
  3268.         NS_ERROR_DOM_WRONG_DOCUMENT_ERR: 0x80530004,
  3269.         NS_ERROR_DOM_INVALID_CHARACTER_ERR: 0x80530005,
  3270.         NS_ERROR_DOM_NO_DATA_ALLOWED_ERR: 0x80530006,
  3271.         NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR: 0x80530007,
  3272.         NS_ERROR_DOM_NOT_FOUND_ERR: 0x80530008,
  3273.         NS_ERROR_DOM_NOT_SUPPORTED_ERR: 0x80530009,
  3274.         NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR: 0x8053000A,
  3275.         NS_ERROR_DOM_INVALID_STATE_ERR: 0x8053000B,
  3276.         NS_ERROR_DOM_SYNTAX_ERR: 0x8053000C,
  3277.         NS_ERROR_DOM_INVALID_MODIFICATION_ERR: 0x8053000D,
  3278.         NS_ERROR_DOM_NAMESPACE_ERR: 0x8053000E,
  3279.         NS_ERROR_DOM_INVALID_ACCESS_ERR: 0x8053000F,
  3280.         NS_ERROR_DOM_VALIDATION_ERR: 0x80530010,
  3281.         NS_ERROR_DOM_TYPE_MISMATCH_ERR: 0x80530011,
  3282.         NS_ERROR_DOM_SECURITY_ERR: 0x805303E8,
  3283.         NS_ERROR_DOM_SECMAN_ERR: 0x805303E9,
  3284.         NS_ERROR_DOM_WRONG_TYPE_ERR: 0x805303EA,
  3285.         NS_ERROR_DOM_NOT_OBJECT_ERR: 0x805303EB,
  3286.         NS_ERROR_DOM_NOT_XPC_OBJECT_ERR: 0x805303EC,
  3287.         NS_ERROR_DOM_NOT_NUMBER_ERR: 0x805303ED,
  3288.         NS_ERROR_DOM_NOT_BOOLEAN_ERR: 0x805303EE,
  3289.         NS_ERROR_DOM_NOT_FUNCTION_ERR: 0x805303EF,
  3290.         NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR: 0x805303F0,
  3291.         NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN: 0x805303F1,
  3292.         NS_ERROR_DOM_PROP_ACCESS_DENIED: 0x805303F2,
  3293.         NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED: 0x805303F3,
  3294.         NS_ERROR_DOM_BAD_URI: 0x805303F4,
  3295.         NS_ERROR_DOM_RETVAL_UNDEFINED: 0x805303F5,
  3296.         NS_ERROR_DOM_QUOTA_REACHED: 0x805303F6,
  3297.         NS_IMAGELIB_ERROR_FAILURE: 0x80540005,
  3298.         NS_IMAGELIB_ERROR_NO_DECODER: 0x80540006,
  3299.         NS_IMAGELIB_ERROR_NOT_FINISHED: 0x80540007,
  3300.         NS_IMAGELIB_ERROR_LOAD_ABORTED: 0x80540008,
  3301.         NS_IMAGELIB_ERROR_NO_ENCODER: 0x80540009,
  3302.         NS_ERROR_EDITOR_NO_SELECTION: 0x80560001,
  3303.         NS_ERROR_EDITOR_NO_TEXTNODE: 0x80560002,
  3304.         NS_FOUND_TARGET: 0x80560003,
  3305.         NS_ERROR_LAUNCHED_CHILD_PROCESS: 0x805800C8,
  3306.         NS_ERROR_LDAP_OPERATIONS_ERROR: 0x80590001,
  3307.         NS_ERROR_LDAP_PROTOCOL_ERROR: 0x80590002,
  3308.         NS_ERROR_LDAP_TIMELIMIT_EXCEEDED: 0x80590003,
  3309.         NS_ERROR_LDAP_SIZELIMIT_EXCEEDED: 0x80590004,
  3310.         NS_ERROR_LDAP_COMPARE_FALSE: 0x80590005,
  3311.         NS_ERROR_LDAP_COMPARE_TRUE: 0x80590006,
  3312.         NS_ERROR_LDAP_STRONG_AUTH_NOT_SUPPORTED: 0x80590007,
  3313.         NS_ERROR_LDAP_STRONG_AUTH_REQUIRED: 0x80590008,
  3314.         NS_ERROR_LDAP_PARTIAL_RESULTS: 0x80590009,
  3315.         NS_ERROR_LDAP_REFERRAL: 0x8059000A,
  3316.         NS_ERROR_LDAP_ADMINLIMIT_EXCEEDED: 0x8059000B,
  3317.         NS_ERROR_LDAP_UNAVAILABLE_CRITICAL_EXTENSION: 0x8059000C,
  3318.         NS_ERROR_LDAP_CONFIDENTIALITY_REQUIRED: 0x8059000D,
  3319.         NS_ERROR_LDAP_SASL_BIND_IN_PROGRESS: 0x8059000E,
  3320.         NS_ERROR_LDAP_NO_SUCH_ATTRIBUTE: 0x80590010,
  3321.         NS_ERROR_LDAP_UNDEFINED_TYPE: 0x80590011,
  3322.         NS_ERROR_LDAP_INAPPROPRIATE_MATCHING: 0x80590012,
  3323.         NS_ERROR_LDAP_CONSTRAINT_VIOLATION: 0x80590013,
  3324.         NS_ERROR_LDAP_TYPE_OR_VALUE_EXISTS: 0x80590014,
  3325.         NS_ERROR_LDAP_INVALID_SYNTAX: 0x80590015,
  3326.         NS_ERROR_LDAP_NO_SUCH_OBJECT: 0x80590020,
  3327.         NS_ERROR_LDAP_ALIAS_PROBLEM: 0x80590021,
  3328.         NS_ERROR_LDAP_INVALID_DN_SYNTAX: 0x80590022,
  3329.         NS_ERROR_LDAP_IS_LEAF: 0x80590023,
  3330.         NS_ERROR_LDAP_ALIAS_DEREF_PROBLEM: 0x80590024,
  3331.         NS_ERROR_LDAP_INAPPROPRIATE_AUTH: 0x80590030,
  3332.         NS_ERROR_LDAP_INVALID_CREDENTIALS: 0x80590031,
  3333.         NS_ERROR_LDAP_INSUFFICIENT_ACCESS: 0x80590032,
  3334.         NS_ERROR_LDAP_BUSY: 0x80590033,
  3335.         NS_ERROR_LDAP_UNAVAILABLE: 0x80590034,
  3336.         NS_ERROR_LDAP_UNWILLING_TO_PERFORM: 0x80590035,
  3337.         NS_ERROR_LDAP_LOOP_DETECT: 0x80590036,
  3338.         NS_ERROR_LDAP_SORT_CONTROL_MISSING: 0x8059003C,
  3339.         NS_ERROR_LDAP_INDEX_RANGE_ERROR: 0x8059003D,
  3340.         NS_ERROR_LDAP_NAMING_VIOLATION: 0x80590040,
  3341.         NS_ERROR_LDAP_OBJECT_CLASS_VIOLATION: 0x80590041,
  3342.         NS_ERROR_LDAP_NOT_ALLOWED_ON_NONLEAF: 0x80590042,
  3343.         NS_ERROR_LDAP_NOT_ALLOWED_ON_RDN: 0x80590043,
  3344.         NS_ERROR_LDAP_ALREADY_EXISTS: 0x80590044,
  3345.         NS_ERROR_LDAP_NO_OBJECT_CLASS_MODS: 0x80590045,
  3346.         NS_ERROR_LDAP_RESULTS_TOO_LARGE: 0x80590046,
  3347.         NS_ERROR_LDAP_AFFECTS_MULTIPLE_DSAS: 0x80590047,
  3348.         NS_ERROR_LDAP_OTHER: 0x80590050,
  3349.         NS_ERROR_LDAP_SERVER_DOWN: 0x80590051,
  3350.         NS_ERROR_LDAP_LOCAL_ERROR: 0x80590052,
  3351.         NS_ERROR_LDAP_ENCODING_ERROR: 0x80590053,
  3352.         NS_ERROR_LDAP_DECODING_ERROR: 0x80590054,
  3353.         NS_ERROR_LDAP_TIMEOUT: 0x80590055,
  3354.         NS_ERROR_LDAP_AUTH_UNKNOWN: 0x80590056,
  3355.         NS_ERROR_LDAP_FILTER_ERROR: 0x80590057,
  3356.         NS_ERROR_LDAP_USER_CANCELLED: 0x80590058,
  3357.         NS_ERROR_LDAP_PARAM_ERROR: 0x80590059,
  3358.         NS_ERROR_LDAP_NO_MEMORY: 0x8059005A,
  3359.         NS_ERROR_LDAP_CONNECT_ERROR: 0x8059005B,
  3360.         NS_ERROR_LDAP_NOT_SUPPORTED: 0x8059005C,
  3361.         NS_ERROR_LDAP_CONTROL_NOT_FOUND: 0x8059005D,
  3362.         NS_ERROR_LDAP_NO_RESULTS_RETURNED: 0x8059005E,
  3363.         NS_ERROR_LDAP_MORE_RESULTS_TO_RETURN: 0x8059005F,
  3364.         NS_ERROR_LDAP_CLIENT_LOOP: 0x80590060,
  3365.         NS_ERROR_LDAP_REFERRAL_LIMIT_EXCEEDED: 0x80590061,
  3366.         NS_ERROR_CMS_VERIFY_NOT_SIGNED: 0x805A0400,
  3367.         NS_ERROR_CMS_VERIFY_NO_CONTENT_INFO: 0x805A0401,
  3368.         NS_ERROR_CMS_VERIFY_BAD_DIGEST: 0x805A0402,
  3369.         NS_ERROR_CMS_VERIFY_NOCERT: 0x805A0404,
  3370.         NS_ERROR_CMS_VERIFY_UNTRUSTED: 0x805A0405,
  3371.         NS_ERROR_CMS_VERIFY_ERROR_UNVERIFIED: 0x805A0407,
  3372.         NS_ERROR_CMS_VERIFY_ERROR_PROCESSING: 0x805A0408,
  3373.         NS_ERROR_CMS_VERIFY_BAD_SIGNATURE: 0x805A0409,
  3374.         NS_ERROR_CMS_VERIFY_DIGEST_MISMATCH: 0x805A040A,
  3375.         NS_ERROR_CMS_VERIFY_UNKNOWN_ALGO: 0x805A040B,
  3376.         NS_ERROR_CMS_VERIFY_UNSUPPORTED_ALGO: 0x805A040C,
  3377.         NS_ERROR_CMS_VERIFY_MALFORMED_SIGNATURE: 0x805A040D,
  3378.         NS_ERROR_CMS_VERIFY_HEADER_MISMATCH: 0x805A040E,
  3379.         NS_ERROR_CMS_VERIFY_NOT_YET_ATTEMPTED: 0x805A040F,
  3380.         NS_ERROR_CMS_VERIFY_CERT_WITHOUT_ADDRESS: 0x805A0410,
  3381.         NS_ERROR_CMS_ENCRYPT_NO_BULK_ALG: 0x805A0420,
  3382.         NS_ERROR_CMS_ENCRYPT_INCOMPLETE: 0x805A0421,
  3383.         NS_ERROR_DOM_INVALID_EXPRESSION_ERR: 0x805B0033,
  3384.         NS_ERROR_DOM_TYPE_ERR: 0x805B0034,
  3385.         NS_ERROR_DOM_RANGE_BAD_BOUNDARYPOINTS_ERR: 0x805C0001,
  3386.         NS_ERROR_DOM_RANGE_INVALID_NODE_TYPE_ERR: 0x805C0002,
  3387.         NS_ERROR_WONT_HANDLE_CONTENT: 0x805D0001,
  3388.         NS_ERROR_MALWARE_URI: 0x805D001E,
  3389.         NS_ERROR_PHISHING_URI: 0x805D001F,
  3390.         NS_ERROR_IMAGE_SRC_CHANGED: 0x805E0008,
  3391.         NS_ERROR_IMAGE_BLOCKED: 0x805E0009,
  3392.         NS_ERROR_CONTENT_BLOCKED: 0x805E000A,
  3393.         NS_ERROR_CONTENT_BLOCKED_SHOW_ALT: 0x805E000B,
  3394.         NS_PROPTABLE_PROP_NOT_THERE: 0x805E000E,
  3395.         TM_ERROR: 0x80600001,
  3396.         NS_ERROR_XSLT_PARSE_FAILURE: 0x80600001,
  3397.         TM_ERROR_WRONG_QUEUE: 0x80600002,
  3398.         NS_ERROR_XPATH_PARSE_FAILURE: 0x80600002,
  3399.         TM_ERROR_NOT_POSTED: 0x80600003,
  3400.         NS_ERROR_XSLT_ALREADY_SET: 0x80600003,
  3401.         TM_ERROR_QUEUE_EXISTS: 0x80600004,
  3402.         NS_ERROR_XSLT_EXECUTION_FAILURE: 0x80600004,
  3403.         NS_ERROR_XPATH_UNKNOWN_FUNCTION: 0x80600005,
  3404.         TM_SUCCESS_DELETE_QUEUE: 0x80600006,
  3405.         NS_ERROR_XSLT_BAD_RECURSION: 0x80600006,
  3406.         NS_ERROR_XSLT_BAD_VALUE: 0x80600007,
  3407.         NS_ERROR_XSLT_NODESET_EXPECTED: 0x80600008,
  3408.         NS_ERROR_XSLT_ABORTED: 0x80600009,
  3409.         NS_ERROR_XSLT_NETWORK_ERROR: 0x8060000A,
  3410.         NS_ERROR_XSLT_WRONG_MIME_TYPE: 0x8060000B,
  3411.         NS_ERROR_XSLT_LOAD_RECURSION: 0x8060000C,
  3412.         NS_ERROR_XPATH_BAD_ARGUMENT_COUNT: 0x8060000D,
  3413.         NS_ERROR_XPATH_BAD_EXTENSION_FUNCTION: 0x8060000E,
  3414.         NS_ERROR_XPATH_PAREN_EXPECTED: 0x8060000F,
  3415.         NS_ERROR_XPATH_INVALID_AXIS: 0x80600010,
  3416.         NS_ERROR_XPATH_NO_NODE_TYPE_TEST: 0x80600011,
  3417.         NS_ERROR_XPATH_BRACKET_EXPECTED: 0x80600012,
  3418.         NS_ERROR_XPATH_INVALID_VAR_NAME: 0x80600013,
  3419.         NS_ERROR_XPATH_UNEXPECTED_END: 0x80600014,
  3420.         NS_ERROR_XPATH_OPERATOR_EXPECTED: 0x80600015,
  3421.         NS_ERROR_XPATH_UNCLOSED_LITERAL: 0x80600016,
  3422.         NS_ERROR_XPATH_BAD_COLON: 0x80600017,
  3423.         NS_ERROR_XPATH_BAD_BANG: 0x80600018,
  3424.         NS_ERROR_XPATH_ILLEGAL_CHAR: 0x80600019,
  3425.         NS_ERROR_XPATH_BINARY_EXPECTED: 0x8060001A,
  3426.         NS_ERROR_XSLT_LOAD_BLOCKED_ERROR: 0x8060001B,
  3427.         NS_ERROR_XPATH_INVALID_EXPRESSION_EVALUATED: 0x8060001C,
  3428.         NS_ERROR_XPATH_UNBALANCED_CURLY_BRACE: 0x8060001D,
  3429.         NS_ERROR_XSLT_BAD_NODE_NAME: 0x8060001E,
  3430.         NS_ERROR_XSLT_VAR_ALREADY_SET: 0x8060001F,
  3431.         NS_ERROR_DOM_SVG_WRONG_TYPE_ERR: 0x80620000,
  3432.         NS_ERROR_DOM_SVG_INVALID_VALUE_ERR: 0x80620001,
  3433.         NS_ERROR_DOM_SVG_MATRIX_NOT_INVERTABLE: 0x80620002,
  3434.         MOZ_ERROR_STORAGE_ERROR: 0x80630001,
  3435.         NS_ERROR_SCHEMAVALIDATOR_NO_SCHEMA_LOADED: 0x80640001,
  3436.         NS_ERROR_SCHEMAVALIDATOR_NO_DOM_NODE_SPECIFIED: 0x80640002,
  3437.         NS_ERROR_SCHEMAVALIDATOR_NO_TYPE_FOUND: 0x80640003,
  3438.         NS_ERROR_SCHEMAVALIDATOR_TYPE_NOT_FOUND: 0x80640004,
  3439.         NS_ERROR_DOM_FILE_NOT_FOUND_ERR: 0x80650000,
  3440.         NS_ERROR_DOM_FILE_NOT_READABLE_ERR: 0x80650001,
  3441.         NS_ERROR_WSDL_NOT_WSDL_ELEMENT: 0x80780001,
  3442.         NS_ERROR_SCHEMA_NOT_SCHEMA_ELEMENT: 0x80780001,
  3443.         NS_ERROR_SCHEMA_NOT_SCHEMA_ELEMENT: 0x80780001,
  3444.         NS_ERROR_DOWNLOAD_COMPLETE: 0x80780001,
  3445.         NS_ERROR_WSDL_SCHEMA_PROCESSING_ERROR: 0x80780002,
  3446.         NS_ERROR_SCHEMA_UNKNOWN_TARGET_NAMESPACE: 0x80780002,
  3447.         NS_ERROR_SCHEMA_UNKNOWN_TARGET_NAMESPACE: 0x80780002,
  3448.         NS_ERROR_DOWNLOAD_NOT_PARTIAL: 0x80780002,
  3449.         NS_ERROR_WSDL_BINDING_NOT_FOUND: 0x80780003,
  3450.         NS_ERROR_SCHEMA_UNKNOWN_TYPE: 0x80780003,
  3451.         NS_ERROR_SCHEMA_UNKNOWN_TYPE: 0x80780003,
  3452.         NS_ERROR_WSDL_UNKNOWN_SCHEMA_COMPONENT: 0x80780004,
  3453.         NS_ERROR_SCHEMA_UNKNOWN_PREFIX: 0x80780004,
  3454.         NS_ERROR_SCHEMA_UNKNOWN_PREFIX: 0x80780004,
  3455.         NS_ERROR_WSDL_UNKNOWN_WSDL_COMPONENT: 0x80780005,
  3456.         NS_ERROR_SCHEMA_INVALID_STRUCTURE: 0x80780005,
  3457.         NS_ERROR_SCHEMA_INVALID_STRUCTURE: 0x80780005,
  3458.         NS_ERROR_WSDL_LOADING_ERROR: 0x80780006,
  3459.         NS_ERROR_SCHEMA_INVALID_TYPE_USAGE: 0x80780006,
  3460.         NS_ERROR_SCHEMA_INVALID_TYPE_USAGE: 0x80780006,
  3461.         NS_ERROR_WSDL_RECURSIVE_IMPORT: 0x80780007,
  3462.         NS_ERROR_SCHEMA_MISSING_TYPE: 0x80780007,
  3463.         NS_ERROR_SCHEMA_MISSING_TYPE: 0x80780007,
  3464.         NS_ERROR_WSDL_NOT_ENABLED: 0x80780008,
  3465.         NS_ERROR_SCHEMA_FACET_VALUE_ERROR: 0x80780008,
  3466.         NS_ERROR_SCHEMA_FACET_VALUE_ERROR: 0x80780008,
  3467.         NS_ERROR_SCHEMA_LOADING_ERROR: 0x80780009,
  3468.         NS_ERROR_SCHEMA_LOADING_ERROR: 0x80780009,
  3469.         IPC_WAIT_NEXT_MESSAGE: 0x8078000A,
  3470.         NS_ERROR_UNORM_MOREOUTPUT: 0x80780021,
  3471.         NS_ERROR_WEBSHELL_REQUEST_REJECTED: 0x807803E9,
  3472.         NS_ERROR_DOCUMENT_IS_PRINTMODE: 0x807807D1,
  3473.         NS_ERROR_XFORMS_CALCUATION_EXCEPTION: 0x80780BB9,
  3474.         NS_ERROR_XFORMS_CALCULATION_EXCEPTION: 0x80780BB9,
  3475.         NS_ERROR_XFORMS_UNION_TYPE: 0x80780BBA
  3476.     }
  3477. }
  3478.  
  3479. /***********************************************************
  3480. module definition (xpcom registration)
  3481. ***********************************************************/
  3482. var HttpFoxServiceModule = 
  3483. {
  3484.     registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
  3485.     {
  3486.         aCompMgr = aCompMgr.
  3487.             QueryInterface(Components.interfaces.nsIComponentRegistrar);
  3488.         aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME, 
  3489.             CONTRACT_ID, aFileSpec, aLocation, aType);
  3490.     },
  3491.  
  3492.     unregisterSelf: function(aCompMgr, aLocation, aType)
  3493.     {
  3494.         aCompMgr = aCompMgr.
  3495.             QueryInterface(Components.interfaces.nsIComponentRegistrar);
  3496.         aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);        
  3497.     },
  3498.  
  3499.     getClassObject: function(aCompMgr, aCID, aIID)
  3500.     {
  3501.         if (!aIID.equals(Components.interfaces.nsIFactory))
  3502.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  3503.  
  3504.         if (aCID.equals(CLASS_ID))
  3505.             return this.HttpFoxServiceFactory;
  3506.  
  3507.         throw Components.results.NS_ERROR_NO_INTERFACE;
  3508.     },
  3509.  
  3510.     canUnload: function(aCompMgr) 
  3511.     { 
  3512.         return true;
  3513.     },
  3514.     
  3515.     /***********************************************************
  3516.     class factory
  3517.  
  3518.     This object is a member of the global-scope Components.classes.
  3519.     It is keyed off of the contract ID. Eg:
  3520.  
  3521.     myHelloWorld = Components.classes["@dietrich.ganx4.com/helloworld;1"].
  3522.                           createInstance(Components.interfaces.nsIHelloWorld);
  3523.  
  3524.     ***********************************************************/
  3525.     HttpFoxServiceFactory:
  3526.     {
  3527.         createInstance: function(aOuter, aIID)
  3528.         {
  3529.             if (aOuter != null)
  3530.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  3531.                 
  3532.             return (new HttpFoxService()).QueryInterface(aIID);
  3533.         }
  3534.     }
  3535. };
  3536.  
  3537. /***********************************************************
  3538. module initialization
  3539.  
  3540. When the application registers the component, this function
  3541. is called.
  3542. ***********************************************************/
  3543. function NSGetModule(aCompMgr, aFileSpec) 
  3544. {
  3545.     return HttpFoxServiceModule;
  3546. }